A brief introduction to git

Clone the github repository:

> git clone git@github.com:plumed/plumed2.git
> cd plumed2

Stay up to date:

> git pull

Make a small fix (working locally):

> git add FILENAME
> git commit FILENAME

Share it (needs internet connection):

> git pull # always check if you are up-to-date
> git push

Look at what's happening:

> git log

or better

> gitk --all

Start working on a new feature, opening a new branch:

> git checkout -b new-feature

List the available branches:

> git branch

Check the available branches including the ones on the origin

> git branch -a

Switch among branches

> git checkout master
> git checkout new-feature

Do a commit on your new-feature branch

> git checkout new-feature
> # now edit NEWFILE
> git add NEWFILE
> git commit NEWFILE

Merge recent work from the master branch, doing a "rebase"

> git checkout master
> git pull # to stay up-to-date with remote work
> git checkout new-feature
> git rebase master

Notice that rebasing is only recommended if your new-feature branch has not been shared yet with other people.

Collect the changes to the log and get rid of branches that have been deleted on the remote repo:

> git fectch --all --prune

After several commits, your new feature is ready for merge.

# checkout the branch you want to merge your work on (e.g. master)
> git checkout master
> git pull # to stay up-to-date with remote work
> git checkout new-feature
# You can squeeze your commits with:
> git rebase -i master
# then interactively picking your commits (follow onscreen instructions)
# (Without -i, all the commits are retained)
# Merge your work into master branch
> git checkout master
> git merge new-feature
# Remove the branch
> git branch -d new-feature
# In case you want to remove a remote branch you should use:emove a remote branch
# > git push origin :crap-branch
# Analyze the results
> gitk --all
# If everything seems right, push your master branch to the central repository
> git push

Checkout a remote branch and switch to it on your local repo

> git checkout -b experimental origin/experimental

Compare list of commits on two different branches (here branches are named master and experimental)

git log master..experimental

All these things can be done with a GUI:

> git gui