You are here

Git & CVS

[ THIS SHOULD DEFINITELY BE ON A SEPARATE PAGE, SO ONE DOESN'T HAVE TO SEE IT ALWAYS WHEN LOOKING FOR GIT DOCUMENTATION ]

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 (https://bitbucket.org/) 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

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 stashgit pullgit 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.

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:

git checkout -p COMMITHASH^ -- FILE_OF_INTEREST

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):