Friday, June 14, 2013

Git Trick: Preview before pull

A little out of sync with your teammates? Not sure if that next git pull is going to send you into a half-hour of merging?

Use git-fetch and git-diff to see what evils await you:

git fetch
git diff origin/master

As usual, difftool can be used to launch a preferred diff utility (*cough*meld*cough*).

git diff origin/master

To see just what files have changed, use the --stat option:

git diff --stat origin/master

...or --dirstat to see what directories have changed:

git diff --dirstat origin/master

With any luck, everything is more or less in sync and you can proceed with your usual git pull.

For those looking for something to add to their .bashrc:

alias git-dry-run='git fetch && git diff --stat origin/master'                  

No comments:

Post a Comment