Today's Question:  What's your opinion about Alibaba mooncake incident?        GIVE A SHOUT

Technical Article => Software =>  Open Source

Frequently used Git commands

  sonic0002      2013-03-11 19:41:06      3,331    0    0

Git configuration

git config --global user.name "robbin"   
git config --global user.email "fankai@gmail.com"
git config --global color.ui true
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global core.editor "mate -w"    # Configure Editor to use textmate
git config -l  #List all configurations

User's git configuration file : ~/.gitconfig

Frequently used Git commands

Check、add、push、delete、find,reset file

git help   # Show help of command
git show            # Show the content pushed one time
git show $id

git co  --    # Drop the modification
git co  .           # Drop the modification

git add       # Add the edited file to the cache
git add .           # Add all the files to the cache

git rm        # Remove file from the version library
git rm  --cached  # Remove file from the cached library, but do not delete the file

git reset     # Reset file
git reset -- .      # 
git reset --hard    # 

git ci 
git ci .
git ci -a           # Combine git add, git rm and git ci
git ci -am "some comments"
git ci --amend      # Amend the last push record

git revert <$id>    # 
git revert HEAD     # 

Check file diff

git diff      # Check the difference between the current file and the cached file
git diff
git diff <$id1> <$id2>   # Check difference between two files
git diff .. # Check difference between two branches
git diff --staged   # 
git diff --cached   # 
git diff --stat     # Just compare statistic difference

Check push records

git log
git log       # Check all the push history of one file
git log -p    # 
git log -p -2       # 
git log --stat      # 

tig

On Mac, you can use tig to substitute diff and log,brew install tig

Git local branch management

Check, switch, create and delete branches

git br -r           # Check remote branch
git br <new_branch> # Create new branch
git br -v           # Check submit information of each branch
git br --merged     # Check the branch which has been merged into the current branch
git br --no-merged  # Check the branch which is not merged into the current branch yet

git co      # Switch to some branch
git co -b <new_branch> # Create a new branch and switch to it
git co -b <new_branch>   # Create new_branch based on branch

git co $id          # checkout one push history
git co $id -b <new_branch>  # checkout one push history and create a new branch

git br -d   # Delete one branch
git br -D   # Force delete one branch

Merge branch and rebase

git merge                # 
git merge origin/master --no-ff  # 

git rebase master        # 
git co  && git rebase master && git co master && git merge 

Git patch management

git diff > ../sync.patch         # Create patch
git apply ../sync.patch          # Apply patch
git apply --check ../sync.patch  # Test patch status

Git stash

git stash                        # stash
git stash list                   # lish stash
git stash apply                  # recover stash
git stash drop                   # delete stash

Git remote branch management

git pull                         #
git pull --no-ff                 # 
git fetch origin                 # 
git merge origin/master          # 
git co --track origin/branch     # 
git co -b <local_branch> origin/<remote_branch>  # 

git push                         # 
git push origin master           # 
git push -u origin master        # 
git push origin <local_branch>   # 
git push origin <local_branch>:<remote_branch>  # 
git push origin :<remote_branch>  

You can use below commands to trace remote library and local library

git branch --set-upstream master origin/master

git branch --set-upstream develop origin/develop

Source : http://robbinfan.com/blog/34/git-common-command

COMMAND GIT

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

  RELATED


  0 COMMENT


No comment for this article.


  WRITE ARTICLE

What an embarrassment

By sonic0002
When someone wants to hire someone with 7-10 years NodeJS experience, the NodeJS author jumped out and said that he had just 7 years experience of NpdeJS because NodeJS was created in 2009, which is 7 years ago. What an embarrassment for the recruiter.