git example page

bayerj edited this page Sep 13, 2010 · 4 revisions
Clone this wiki locally

Getting your fork

Once you have forked pybrain/pybrain via the github web interface, you can clone it locally:

git clone<your-username>/pybrain.git

Commiting your changes to your fork

After you have done some changes locally to your code, you can push them back to your github fork:

$ git commit -a -m "Awesome change implemented!"
$ git push

Adding the central repository as a remote and getting changes from it

Remotes are bookmarks to clones/forks/repositories in different directories (possibly on different computers). This are always identified by an URL, which might be a webadress, a ssh adress or a local file system path. E.g. you can add the central PyBrain as a remote:

$ git remote add central git://

After that, you can fetch changes from the central repository and merge them into your local clone. (This examples assumes that you want changes from the master branch.)

$ git fetch central
$ git merge central/master

To do both commands in one swipe, you can also do:

$ git pull central master

What has happened in the central repository since I checked last?

Make sure you have added the pybrain/pybrain repositry as the remote central. This command gives you a list of the differing changesets between the central master branch and your master branch.

$ git fetch central
$ git cherry -v central/master master

If you want diff outputs, you can do:

$ git fetch central
$ git diff central/master master

Programming together with your colleague right next to you

Getting access to another’s repository

There is three easy ways:

  1. Either of you gives the other one an ssh account with read/write access to his repository
  2. Either of you exposes the repository directory over the network
  3. Either of you starts a web server (lighttpd installation required)

In case of the first method, you will come up with an url similar to the following:


In the second case, it will just be a normal file system path. In the last case, you can use

$ git instaweb --start

which starts a webserver at


Adding a remote and pulling changes

All these urls can be used to add another remote to github. Say Alice and Bob want to cooperate working on a branch cake. Alice then can add Bob as a remote via

$ git remote add bob <the-url-from-previous-section>

In order to merge in Bob’s changes, she can always do

$ git pull bob cake

and git will fetch and merge in any changes Bob has committed on his side.

Preparing a patch for email sending

Make sure you have added the pybrain/pybrain repository as the remote central as explained above. Then pull all changes from the central repository to get up-to-date:

$ git pull central

Generate a set of patch files containing all the changesets in some directory by using:

$ git format-patch -o <some-directory> central/master

you can then either zip those files up and send them to someone (e.g. :) or use git for this (if you have sendmail configured correctly):

$ git send-email --from <your-email> --to <some-directory-as-above>