Legacy post. This article was written between 2016 and 2018. Software versions, commands and services mentioned here may be outdated. Check the official documentation before running anything.
Useful commands
My useful commands
gitg
git graph -a
- Rename last commit
git commit --amend
or
git rebase -i HEAD~1
- Squash 2 commits into one
git rebase -i HEAD~2
git rebase --interactive --root
- Set the core editor
git config --global core.editor "vim"
- Stash
git stash
git stash apply
git log
- Rename branch
git branch -m old new
- Create branch
- git checkout -b
- Revert last commit
git reset HEAD~1 --hard
- Rebase commit history
git rebase develop
- Config
git remote set-url origin git@github.com:your_username/your_project.git
git config user.name "foo"
git config user.email "foo@bar.com"
Most useful git config commands
- List all branches
git branch -a
- Force overwrite origin
git push --force-with-lease
- Push and track local branch to origin
git push --set-upstream origin feature/jls-INGFUN-1219-StoryboardLoggingBadVolumeId
- Rewrite commit information
git commit --amend --date="Sun Feb 12 17:22 2017 +0100"
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='username' GIT_AUTHOR_EMAIL='foo@bar.com'; GIT_COMMITTER_NAME='username'; GIT_COMMITTER_EMAIL='foo@bar.com'"
git filter-branch -f --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='username' GIT_AUTHOR_EMAIL='foo@bar.com'; GIT_COMMITTER_NAME='username'; GIT_COMMITTER_EMAIL='foo@bar.com';GIT_COMMITTER_DATE='Sun Feb 12 17:22 2017 +0100';GIT_AUTHOR_DATE='Sun Feb 12 17:22 2017 +0100'"
- Check out a remote branch
git checkout -b develop origin/develop
- Show full log information
git log --format=fuller
- Create tags
git tag -a 1.3 -m "v1.3"
git push --tags