Recent Changes - Search:




This is the beginnings of a ‘cheat sheet’ for commonly used git commands.

Branching model:

Handling merge conflicts:

Using the ‘rebase’ command:

How to undo (almost) anything with Git:

Squash several Git commits into a single commit:

Web view with gitphp

Reverting a commit

  • In the ordinary case you want to generate a new commit that reverts the changes with git revert <commit>

If you haven’t pushed your commit yet, then there are a few options.

Do not do this if you have already pushed your commit!

  • Amend the existing commit with git commit --ammend.
  • Revert the most recent commit: git reset HEAD~

If you have pushed the commit upstream, but if there are no other users of the brach

  • you can do some surgery on it and rewind the history by git reset --hard <commit> followed by git push origin -f

To undo changes on your local repo, and set your branch to exactly match the remote branch: git fetch origin followed by git reset --hard origin/master


  • List all branches: git branch
  • Switch to a branch: git checkout <branch>
  • Create a new local branch with git branch <branch>
  • Add branch to the remote repository: git push origin <branch>
  • Delete a local branch with git branch -d <branch>
  • Delete a local branch even if it has unmerged changes (throws them away), git branch -D <branch>
  • Delete a remote branch with git push origin --delete <branch>
  • Rename the current branch git branch -m <branch>
  • Compare two branches, from the HEAD of the first branch to the HEAD of the second git diff branch1..branch2
  • Compare commits on two branches git log branch1..branch2
  • Compare the change in a branch2 from the common ancestor of branch1 and branch2 git diff branch1...branch2
  • Compare a specific file between two branches git diff master..feature -- <file>
  • To rename a branch, git branch -m old_branchname new_branchname followed by git push origin :old_branchname new_branchname Might also need git push --set-upstream origin new_branchname
Edit - History - Print - Recent Changes - Search
Page last modified on April 12, 2020, at 01:25 AM