Git usage

From Planets
Jump to: navigation, search

This page is a guide to use the git repository correctly. An advanced user guide is available in the gitlab wiki.

Access

First of all, you will probably need to connect via the "CC-IN2P3 single sign on" button and your institutional account ("EDUGAIN"). You can then either clone the git repository via SSH:

git clone git@gitlab.in2p3.fr:la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git

or via https if you do not have an ssh key and will not require to push often/do not want to.

git clone https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git

Setup and link with svn (highly recommended if not required)

Simply follow the README.md at the root folder of the repository, i.e., run the following script to setup the git:

./UTIL/git_init.sh

This will connect the git with the svn (git-svn is a pre-requisite). This will allow you to commit and get changes from the svn repository each time you use the git push command. A second git push is required to effectively push the new commits (hashes may have changed) on the remote git repository.

Simple commands

As for svn, git is used to fetch remote changes from the repository:

git pull

If you want to send your changes to the repository, you will need to commit and push. You should first add the concerned files via:

git add <list-files>

Note that you can therefore choose to break down your changes to meaningful commits (recommended, to better follow what each commit is doing). Then you can commit the files once you're satisfied via:

git commit -m "A grand message to explain what this is all about."

You can make multiple commits like this locally, but note they have not been sent to the repository (yet). Once you're ready to send your whole bunch of commits to the server, you can use:

git push

This will synchronize your local branch to the remote branch.

Branches

It is recommended to work with branches in git. For that, select an existing <branch> with:

git checkout <branch>

The default is master. To create a new branch, you can do:

git checkout -b <branch>

A good idea would be to name it YI/meaningful_name, where YI are Your Initials (in lowercase).

Push a new branch to the remote repository like this:

git push origin <branch>

You can import the updates of the master onto your local branch. It would be recommended to do it in a fast-forward fashion, to keep a linear history. This can be done using:

git pull --rebase master

Such changes could change the commits history, and if you had pushed commits onto your remote branch already, you might need to force-push your changes:

git push --force

Save your local changes before changing branches

In case you do not want to push your local changes before changing branches or pulling/pushing you can do

git stash         # stash away your changes temporarily
git checkout / git pull   / git push
git stash pop     # get back your changes


Merge-request

Once you feel your local branch could be shared to others and merged back into the main branch (master), the recommended procedure is to create a merge-request on the gitlab. To be able to synchronize with the svn, please select the option "fast-forward", to keep a linear history.


TODO: looks like not everyone has the right to make a merge-request?

git configuration

You can configure git to get useful shortcuts via the addition of the .gitconfig file in your home directory. Example below (replace all <text> by your own):

[user]
	name = <Titi Toto>
	email = <titototo@gmail.com>

[alias]
	br = branch
	ci = commit
	co = checkout
	ph = push
	pl = pull --rebase
	pll = merge --ff-only
	list = ls-tree --name-only HEAD
	ls = log --no-decorate --graph --abbrev-commit --pretty=format:'%ar %h - %an: %s'
	st = status
	stt = status .
[push]
	default = matching
[http]
	sslVerify = false
[credential]
	helper = store
	username=<username>
[color]
	ui = auto
[cola]
	spellcheck = false

Issues

You can track issues on the issues page.