Difference between revisions of "Git usage"

From Planets
Jump to: navigation, search
m (Merge-request)
(Access)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
This page is a guide to use the [https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk ''git repository''] correctly.
 
This page is a guide to use the [https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk ''git repository''] correctly.
 +
An advanced user guide is available in [https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk/-/wikis/home ''the gitlab wiki''].
  
 
== Access ==
 
== Access ==
Line 8: Line 9:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone git@gitlab.in2p3.fr:la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git
 
git clone git@gitlab.in2p3.fr:la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git
 +
cd git-trunk
 +
./UTIL/git_init.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 13: Line 16:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git
 
git clone https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk.git
 +
cd git-trunk
 +
./UTIL/git_init.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Note that running the '''[[Git-svn|git_init.sh]]''' script is <u>required</u> if you want to [[#Simple commands|push]] your work to the project.
 +
It will [[git-svn|setup the repository and link git with svn]] ([[git-svn]] is a pre-requisite).
 +
 +
The [[Git-svn|git_init.sh script]] will allow you to:
 +
* synchronize the local git master branch with the svn repository, each time you use the '''git push''' command.
 +
* push local commits to the git remote master branch the '''2nd time''' you use '''git push''' ([[Git-svn#pre-push hook|too much information just in case: the first push changes the hashes of each new local git commit to add the revision number of the svn commit, which therefore requires a 2nd push]]).
  
 
== Simple commands ==  
 
== Simple commands ==  
  
As for [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/Some_pointers_about_the_subversion_(svn)_tool ''svn''], git is used to fetch remote changes from the repository:
+
As for [[Some_pointers_about_the_subversion_(svn)_tool|svn]], git is used to fetch remote changes from the repository:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git pull
 
git pull
Line 66: Line 78:
 
git push --force
 
git push --force
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== 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
 +
 +
<syntaxhighlight lang="bash">
 +
git stash        # stash away your changes temporarily
 +
git checkout / git pull  / git push
 +
git stash pop    # get back your changes
 +
</syntaxhighlight>
 +
  
 
== Merge-request ==
 
== Merge-request ==
Line 110: Line 133:
 
== Issues ==
 
== Issues ==
 
You can track issues on the [https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk/-/issues ''issues''] page.
 
You can track issues on the [https://gitlab.in2p3.fr/la-communaut-des-mod-les-atmosph-riques-plan-taires/git-trunk/-/issues ''issues''] page.
 +
 +
[[Category:FAQ]]

Latest revision as of 17:49, 13 December 2024

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
cd git-trunk
./UTIL/git_init.sh

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
cd git-trunk
./UTIL/git_init.sh

Note that running the git_init.sh script is required if you want to push your work to the project. It will setup the repository and link git with svn (git-svn is a pre-requisite).

The git_init.sh script will allow you to:

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.