Skip to content
hatcherfangPublic

About

git command

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Git command

refer url http://stormzhang.com/github/2016/05/30/learn-github-from-zero3/

  • git init //init github repository
  • git status //check git status
  • git add //add into cache
  • git rm --cached //remove from cache
  • git commit -m "commit info" // commit with commit info
  • git log //to check commit log

Branch function: to make different feature develop independent.

  • git branch // to create a new branch named
  • git checkout // to switch to branch
  • git checkout -b // to renew a branch and auto-switch to it.
  • list all of the branch
    git branch -a
  • fetch remote branch to local, if branchname not exist in local, it will be created
    git fetch origin "remote-branchname":"local-branchname"
  • checkout remote branch to local and switch to the branch
    git checkout origin/"remote-branchname" -b "local-branchname"

Merge switch branch to master branch step

  • git checkout master // first switch branch to master
  • git merge // second merge to master
  • git branch -d // to delete branch
  • git branch -D // to force delete branch
# delete remote branch  
git branch -r -d origin/branch-name 
git push origin :branch-name

Tag function: to traceback errors.

  • git tag // to show tags
  • git tag // to renew a tag named
  • git checkout // to switch the tag to
  • git tag -a -m "comment" // to add annotated tag with comment
  • git tag -d // delete local tag
  • git push origin :refs/tags/ // delete remote tag
  • git push origin // to commit tag

Login github and submit code to github

to set the authentication refer http://stormzhang.com/github/2016/06/04/learn-github-from-zero4/

  • git clone git@github.com:/.git // to get the remote repository
  • git remote add origin git@github.com:/.git //to attach local repository with remote's
  • git remote -v // to show the remote repository name
  • git push origin master // to push local code to remote master branch
  • git pull origin master // to update local code with remote branch. We usually first pull the remote code to local before push.

Set the git username and email which will be shown on commit info

  • git config --global user.name "hatcherfang"
  • git config --global user.email "hatcherfang@163.com"
  • to check the config file vim .git/config

Git code update

  • git fetch git@github.com:/.git // to update the local repository
  • git diff // to diff the file with updated
  • git rm // to remove the file from repository
  • git mv // to rename the to
  1. Checked for existing SSH keys
    ls ~/.ssh/
    If id_rsa.pub not exists, go to step 2.

  2. Generated a new SSH key and added it to the ssh-agent

  • ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • ssh-add ~/.ssh/id_rsa
  1. copy SSH key id_rsa.pub(~/.ssh/id_rsa.pub) to your github account
  2. try to use git clone repo path to download code

Git workflow

workflow

git checkout -b my-test //create local branch my-test under current branch
git push origin my-test //push my-test branch to remote
git branch --set-upstream-to=origin/my-test //将本地分支my-test关联到远程分支my-test上
git branch -a // to check remote branch

About

git command

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors