Skip to content

Instantly share code, notes, and snippets.

@mislav mislav/git.md
Last active Oct 30, 2018

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Feb 27, 2018

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.