Useful commands

Most useful git commands

My useful commands

gitg
git graph -a
  • Rename last commit
git commit --amend

or

git rebase -i HEAD~1
  • Squash 2 commits in one
git rebase -i HEAD~2
git rebase --interactive --root
  • Set 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 config remote.origin.url 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 branch
git branch -a
  • Force overwrite origin
git push --force
  • 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'"
  • Checkout 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

Tags:

Categories:

Updated: