A primer on remote branches with Git

Tags:

Here we assume that

  1. You have set up a local working directory to edit the source code of Simutrans-Experimental, your favorite game; and

  2. Tou would like to compile one of the branches to test it.

First, setup git. Now we go get James's repository:

$ git clone https://github.com/jamespetts/simutrans-experimental

List remote branches only:

$ git branch -r

List all remote branches, and lots of other info:

$ git remote show origin

Create a local branch to track a remote branch:

$ git branch --track running-powers origin/running-powers

Have our local working copy, track the named branch:

$ git checkout running-powers

Go get it

$ git pull

Show local branches:

$ git branch
10.x
master
* running-powers

OK let's build that:

$ make -j3
[...]
===> LD build/default/simutrans-experimental

Cool! Now, copy that binary to our games-playing directory:

$ cp -a build/default/simutrans-experimental ~/simutrans/sim-exp/

If some git commands refuse to proceed because they’re worried about clobbering untracked files, and you’re certain that all untracked files and directories are expendable, then delete them mercilessly with:

$ git clean -f -d

What will happen if I 'git fetch' or 'git pull'?

Tags:

If you have used svn for years, git can seem a little strange.

Half the problem is the different mindset -- let's tackle one common problem: How do I know what will happen if I do a git fetch or a git pull? First let's do a status:

$ git status
# On branch master
# Your branch is behind 'origin/master' by 3 commits,
  and can be fast-forwarded.

That's a lot friendlier than svn's equivalent svn diff. And that status gives us the clue as to what we would like to compare: it's simply our copy (master) and the one it's "behind" (origin/master). So if we request:

$ git diff master origin/master

we will get a nice difference between our copy (shown in the diff with -) and the remote (shown with +).

See also, these comments on stackoverflow and the Git Cheat Sheet