Getting started

You will need a username and password from Antony L.

Making changes

Use git status to view which files in your local copy have changed. Files which are not tracked do not matter (and will not be added unless you explicitly git add filename). To commit changes do
git commit -a -m "my change description"
Use "git log" to see recent changes. Changes are stored locally, if they are for public consumption do
git pull origin master
git push origin master
The first line downloads any changes from other people. If there are conflicts search for ">>>" in in the source files and edit by hand to resolve, and commit. The second line pushes changes to the shared repository.

"git add --all" will add all files (you may well not want this - don't add lots of junk by mistake!), or use "git add xx" to add individual files or folders.

Undo local changes

To revert a file to the state in the latest commit, just do git checkout filename or git checkout path. This is useful to avoid conflicts with local changes before pulling from the remote repository. Of course if you want the local changes you should commit them, or save in a new branch (see also branching and git reset below).

CAMB and CAMB Sources

The camb repository has CAMB and CAMB sources (CAMB_sources branch). Plain CAMB is also in the CosmoMC repository but may not be as up to date

General Help

Many helpful websites document git, eg. Cheat Sheet, Community book, Git Magic.

Tags

Official code releases are tagged, so you can easily check out a particular version.

Make a tag e.g.

git tag May2010 c24bda0cfac567a1a5bb7844e25631aed53f756e
(use "git log" to get the commit you want to tag). Must use "git push --tags" to push to public server, not included in normal pushes.

Make or use a branch

For add-ons and customized versions you can make a branch from the main code.

Use "git fetch" to check your list of branches is up to date. List available branches using:

git branch -r
For details see e.g. Branch Wizardry.

Make your own new branch

Starting from an unmodified branch that you have checked out, do
git branch NewBranch
checkout NewBranch
to make NewBranch which also contains the current state, and then switch to it. You can make changes to your new branch independently of the original branch. To use an old version you can can also do, eg.
git branch NewBranch Jan2010
If you have already modified code in the current branch which you have not committed, and want to put it in a new branch instead, do
git checkout -b new_branch_name

Load code for a particular branch

Switching branches is easy, just do
git checkout branch_name

Customized versions and updates

For customized versions probably best to branch from version which custom version closest matches, and then do merge from master to update it:
git branch NewBranch Jan2010
git checkout NewBranch
Now make your changes. If you have old modified source code you can replace files with your modified versions.

Use "git add xx" to add new files. Then save changes using

git commit -m "my first custom version"

If you started from an old branch, or there have been subsequent updates to the main code, try to update to be consistent:

git pull origin master

Branches are stored locally when you make them, no one else can see them. Push your modified branch to the git repository to share (use push -u to make it track by default, so pull and push is then easier):

git push origin NewBranch
This makes a new branch NewBranch on the remote repository, and will not mess up the master branch. If other people also push changes, you pull them using
git pull origin NewBranch

(make sure current branch is branch you want to update). You can also pull changes to the master branch into your custom branch, e.g. with your local NewBranch checked out "git pull origin master" will update local NewBranch with changes from the latest remote master branch. If someone has messed up your beautiful code, use "git log" to view the history, checkout the last version that was OK, or use git diff" to see actual changes and make a new commit correcting them if need be. Viewing changes is easier with a GUI, TortoiseGit, XCode, Visual Studio and others all have nice ways of displaying changes.

You always need to commit changes before switching branches, or pushing your changes.

If you have multiple branches, and want to update the current branch with changes from another, you can use

git merge OtherBranch
If there are whitespace changes you can ignore them with
git merge -Xignore-all-space test_update_branch
You may want to add --no-commit --no-ff to allow fixing the whitespace consistently before committing the merge. CosmoMC source files have standardized whitespace and indenting from Visual Studio's Format Document, but older versions do not.

If a branch you are merging contains lots of commits, you can combine into one new commit by using

git merge --squash MergeBranch
(and then using commit -m "new commit message").

Undoing mistakes and branch management

Use "git log" to view the history of changes. To undo a mistake, and committed the mistake, reset from commit shown in git log
git reset --hard <commit>

You can also revert a local branch to a remote branch
git reset --hard origin/NewBranch
Note these will delete all your local changes. If you've already pushed you bad changes, and hence messed up the public branch, you can force replacement of remote branch with local branch
git push --force origin NewBranch
Don't do this if anyone is likely to have used the remote copy though. If mistakes have been shared, better to have a new commit which is a correction (see "reset").

Delete remote branch with

git push --delete origin NewBranch
or
git push origin :NewBranch
To stop the branch still showing up in "branch -r" do git remote prune origin

If you merged the wrong branch, or did the wrong pull, you can undo a (fast forward) merge or pull reverting to previous state with

git reset --keep NewBranch@{1}

Reset single uncommitted file to the last committed version with

git checkout file

Make new branch using un-committed changes

git checkout -b new_branch_name
(does not change your local modified files; after new branch is made, commit)

Permissions

There's no way to restrict permissions on a branch basis. Only on the level of repositories. Some people have read-only git access, people who are developing branches or contributing have write access; anyone with write access can write to any branch.