Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active May 20, 2020 14:52
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mislav/5147811 to your computer and use it in GitHub Desktop.
Save mislav/5147811 to your computer and use it in GitHub Desktop.
git merge, reset, rebase, checkout

What I believe is the most confusing thing for git beginners is that the main commands have multiple uses depending on the arguments or context, and some of those uses aren't well-described by the command's name.

Merge

  • merges together different branches (different histories, to be more exact)
  • fast-forwards if a merge isn't necessary; effectively repositioning the branch head to a descendant commit
  • unwanted outcome of git pull

Rebase

  • replays a set of commits as if they were based off another parent
  • interactively used for history cleanup: reorder & squash related commits
  • should be used for git pull instead of merge

Reset

  • resets (unstages) changes added to the index; undoes git add
  • repositions the branch head to another commit; optionally resetting index & working tree
    • undo a commit, either discarding changes or keeping them for the next commit
    • discard all working copy changes since the last commit

Checkout

  • switch branches
    • create a new branch and switch to it
  • checkout a file or directory as it were in another commit
    • discard all working copy changes since the last commit
    • resolve merge conflicts
@Raz240
Copy link

Raz240 commented Feb 27, 2018

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment