Last active
December 17, 2015 11:49
-
-
Save iyunbo/5605116 to your computer and use it in GitHub Desktop.
Git most used commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I am assigned a issue, let me create a new branch and switch to it for working on issue 53 | |
git checkout -b iss53 | |
# Switch back to production because something goes wrong | |
git checkout master | |
# Create a hotfix branch to fix the stuff | |
git checkout -b hotfix | |
# After fixed, I go back to master again and merge the hotfix | |
git checkout master | |
git merge hotfix | |
# After the hotfix version has been deployed, get rid of the merged branch | |
git branch -d hotfix | |
# OK, let's take a break, nice, the bug is fixed and I can go back to work on my unfinished issue | |
git checkout iss53 | |
# It turns out that the hotfix I did is important to my issue too, so merge it from the master | |
git merge master | |
# The merge did not complete succesefully due to some conflicts, I have to resolve them myself | |
git mergetool | |
# Merge done! check it out | |
git status | |
# Everything is fine, I can finally commit them | |
git commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<type>(<scope>): <subject> | |
<body> | |
<footer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#make git easier to use! | |
wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash > ~/.git-completon.bash | |
echo "source ~/.git-completion.bash" >> ~/.bashrc | |
git config --global alias.co checkout | |
git config --global alias.br branch | |
git config --global alias.ci commit | |
git config --global alias.st status | |
git config --global alias.unstage 'reset HEAD --' | |
git config --global alias.last 'log -1 HEAD' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To view latest 5 commits history | |
git log -5 | |
#To view latest 5 commits history with inline changes | |
git log -5 -U1 --word-diff | |
#To show statistics since 2 weeks | |
git log --stat --since=2.weeks | |
#Git graph | |
git log --pretty=format:"%h %s" --graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To figure out the patches from the common ancestor of the client and server branches, and then replay them onto master | |
git rebase --onto master server client | |
#Now you can fast-forward your master branch | |
git checkout master | |
git merge client | |
#Then rebase and merge server as well | |
git rebase master server | |
git checkout master | |
git merge server | |
#Goodbye merged branches | |
git branch -d client | |
git branch -d server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To begin tracking the README file | |
git add README | |
#To check files states | |
git status | |
#To view last changes | |
git diff | |
#To add everything from current directory to stage | |
git add . | |
#To remove README from the stage but keep it in the working tree | |
git rm --cached README |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To show server infomation | |
git remote -v | |
#To add a remote repository, this is something SVN can not do: the same directory manage multiple remote repository | |
git remote add iyunbo git://github.com/iyunbo/iyunbo.git | |
#To get data from the remote projects | |
git fetch [remote-name] | |
#To fetch and merge data from the remote | |
git pull | |
#To upload your data to the remote | |
git push | |
#To inspect a remote | |
git remote show origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To show the tags of some pattern | |
git tag -l 'v1.4.2.*' | |
#To create a annotated tag | |
git tag -a v1.4 -m 'my version 1.4' | |
#To share tags | |
git push origin --tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To change the last commit | |
git commit --amend | |
#To unstage a staged file | |
git reset HEAD file.txt | |
#To unmodify a modified file, this is a dangerous command: any changes you made to that file are gone | |
git checkout -- file.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment