Git & CVS

CVS - few key commands, mention central repository for e.g. IDL



Getting started with Git and BitBucket

Git is a version-tracker that allows non-linear workflows, which is perfect for collaborative works (not only for code, but also for e.g. LaTeX documents).

Git tracks the modifications of your code on your local machine and synchronizes your work with a remote repository.

Bitbucket ( is a collection of remote repositories and should be used together with a version-tracker like Git. Note here that other repositories, such as github, don't allow private repository, but you are forced to share your contents unless you pay a monthly fee.

Configuring a repository project from scratch

First of all install Git on your local machine. For linux users this is

sudo apt-get install git

For the best readability turn on the syntax highlighting. This is not mandatory but helps a lot

git config --global color.ui "auto"

After this step you are ready to configure your local username and email

git config --global "Your Name"

git config --global "your@email.address"

Then register on Bitbucket (

IMPORTANT: registration on bitbucket is free only if you are affiliated with an academic institution, hence use your NBI email: it will be automatically recognized as academic.

Once you are registered start a new repository here (or using CREATE button in the top bar).

Now you can follow the default instruction from the bitbucket webpage.  In particular, to "clone" a copy of the repository on a new host, do

git clone

Basic commands

Important commands are

git status

which shows the files modified/created/removed that are not committed yet (in red).

To show the diff of the new modifications use

git diff

that can be employed also for single files using

git diff [file list including wildchar]

This command is very useful when you want to check what you changed before committing it.


To add these files (or a part of them) to the next commit use

git add [file list including wildchar]

To do the same interactively, use

git add -p [nothing -- or file list including wildchar]

Note that to add all the files to the next commit you can use

git add .

To remove or move files, use

git rm [file list including wildchar]

git mv file-or-dir-source file-or-dir-desination


Note that after adding/removing files if you type again

git status

the added files are green.


Now commit the changes to the local repository, with an explanatory comment,

git commit -m "my wonderful changes"

and push it to (synchronize with) the remote repository (although this need not be done for every commit):

git push

where a password could be required (if private repository, or restricted push).  

If you have made several local commits you may want to merge them to fewer commits before pushing.  To merge the last 4 commits interactively, do

git rebase -i HEAD~4

If you just want to correct the last commit message, you can instead do

git commit --amend


To undo changes check this guide (which is also very clear for other git-bitbucket operations)


To synchronize your local repository with the bitbucket remote repository just use

git pull

a password could be required (if private repository).


If you have local changes that are not yet committed, then use these commands to temporarily hide ("stash") them, while doing the pull:

git stash
git pull
git stash pop

and then add + commit (+ push).   In general, it is a good idea to avoid colliding edits, since it complicates interpreting the history and log of changes.

The SourceTree and SmartGid Graphical User Interfaces

Instead of, or as a complement to using the GIT command line interface you may want to install the SourceTree (MacOs, Windows) or SmartGit (Linux, MacOs, Windows) Graphical User Interfaces, which give helpful graphical overviews of your repositories.  Git GUIs are particularly helpful in handling separate edits ("chunks") in source code files, and also simplifies viewing changes and log messages.

FireFox add-on

No, this isn't Facebook

The bitbucket interface looks very similar to Facebook. In order to avoid this misunderstanding with non-bitbucket users you can install the stylish add-on for firefox ( with the following theme



Git Cookbook

This page is intended to serve as a place where we can collect useful recipes for git.

To see a graphic representation of commits, marked with branch names and tags:

git log --all --tags --graph --decorate

(you may want to create an alias for this). On a laptop you may prefer to use instead use SourceTree (MacOS, Windows) or SmartGit (Linux, MacOs, Windows).

Want to see who last modified a specific line and when?

git blame -L115,+20 -- FILENAME

This will show changs to lines 115 --> 115+20 in `filename.f90`.

Do you want to revert one or more changes from a commit (but not the whole commit)? You can do the following:


This will launch an interactive diff where you can selectively apply the "hulks" (changes) from COMMITHASH to the current version. Select y (for yes) to choose the version from COMMITHASH, or n (for no) to keep the current version. COMMITHASH is the git hash for the commit of interest. More information can be found in man git-add, in the "INTERACTIVE MODE" section, sub-section "patch".

How to do a git "dry run" of a merge (i.e., see what changes will be made without actually making them):

Pull changes but don't merge:

git fetch origin branch/feature

Output to TTY:

git diff HEAD..origin/branch/feature

If you want to use a specific (GUI) tool (like meld):

git difftool HEAD..origin/branch/feature