Thursday, 22 December 2011

Breaking up git-pull

Up until now, whenever I wanted to clean up mistakes in a branch on my local repo I had been executing the following:

% git checkout master
% git pull origin +master

Which has forced the update from my remote origin branch, wiping anything locally and reverting me back to where I wanted to be.

So since git-pull is really just a convenience wrapper around git fetch & merge, I was always curious about the real commands were behind the git pull, and finally figured it out:

% git fetch -u origin +master

The key pieces meaning:

  • + - force a fetch regardless of whether the branch is a descendant of the current branch. This is required because your trying to rewrite history.
  • -u - update the current HEAD. Without this git will refuse to do the operation.

No comments:

Post a Comment