Git usage

From Planets
Revision as of 15:36, 4 April 2024 by Aurelien.falco (talk | contribs) (Simple commands)

Jump to: navigation, search

This page is a guide to use the git repository correctly.

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

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

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.

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.