South Green Logo

South Green tutorials pages

Git For Dummies


This page describes describes the main commands you need in order to use Git.

Author(s)

Authors Christine Tranchant-Dubreuil
Research Unit UMR DIADE
Institut

Keywords

git

Date

10/03/2017


Summary

Download the repository using the git clonecommand

 git clone https://github.com/SouthGreenPlatform/TOGGLE-DEV.git <directory name>
#Example
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git clone https://github.com/SouthGreenPlatform/TOGGLE-DEV.git .
Cloning into '.'...
remote: Counting objects: 7945, done.
remote: Compressing objects: 100% (124/124), done.
remote: Total 7945 (delta 78), reused 0 (delta 0), pack-reused 7820
Receiving objects: 100% (7945/7945), 170.06 MiB | 23.03 MiB/s, done.
Resolving deltas: 100% (5503/5503), done.
Checking out files: 100% (364/364), done.

Update the downloaded repository using the git pull command

update your copy of repository with the version on remote server

 git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git <branch name>

`

#Example
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git  master
From https://github.com/SouthGreenPlatform/TOGGLE-DEV
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Add a file, commit and pull with git add, git commit and git pull

Don’t forget to pull to download the latest changes before pushing

To add a file (a change) to your local index with git add

git add <filename>

To actually commit these changes with git commit

git commit -m "message" <file name>

To send those changes to your remote repository with git pull

git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git <branch_name>

Example

[tranchant@master0 TOGGLE-ON-THE-FLY]$ git add update.txt

[tranchant@master0 TOGGLE-ON-THE-FLY]$ git commit -m "Adding update.txt file" update.txt
[master ebb0a1c] Adding update.txt file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 update.txt

[tranchant@master0 TOGGLE-ON-THE-FLY]$ git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 271 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local objects.
To https://github.com/SouthGreenPlatform/TOGGLE-DEV.git
   fec3a1f..ebb0a1c  master -> master

Remove a file using git rm

git rm <file name>
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git rm update.txt
rm 'update.txt'

[tranchant@master0 TOGGLE-ON-THE-FLY]$ git commit -m "Remove update.txt file" update.txt
[master 9fa50b4] Remove update.txt file
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 update.txt

[tranchant@master0 TOGGLE-ON-THE-FLY]$ git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 236 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local objects.
To https://github.com/SouthGreenPlatform/TOGGLE-DEV.git
   ebb0a1c..9fa50b4  master -> master

Branching

Branches are used to develop new features or modify codes isolated from each other. The master branch is the “default” branch when a repository is created. Use other branches for development and merge them back to the master branch.

View all branches that were ever checked out on your local copy using ` git branch `

git branch
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git branch
* master

View all distant branches using ` git branch `

git branch -r
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/picardtools-samtofastq
  origin/samtoolsBlocks
  origin/structuralVariant
  origin/tgicl
  origin/transabyss
  origin/trinity

Create your own branch on your local copy then transfer it on remote server

Create the branch

git branch <branch name>

Move into this branch

git checkout <branch name>

Commit the changes

git commit -m "mon commentaire"

Push this local branch on the remote server

 git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git nom_branche

Get a distant branch on the local repository if the branch don’t exist locally

Method 1

git checkout <remote branch name>
git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git nom_branche_distante `

Method 2

git branch <remote branch name>
git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git <remote branch name>
git checkout <remote branch name>

To merge another branch (ex: samtoolsBlock) into your active branch (e.g. master)

Move into the “active” branch (e.g. master)

git checkout master

Update your local repository to the newest commit,

git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master

Merging

git merge samtoolsBlock

`

Check and resolve the conflicts generated

You are responsible to merge those conflicts manually by editing the files shown by git status.

 git status

Commit and push the changes and the merge on the distant server

 git commit -m "Branch merging samtoolsBlock-master" -a
 git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master `

Remove a branche

on the remote server

 git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git :nom_branche_a_suppr `

`

on our local copy

git branch nom-branche_a_suppr -d

`

Back to the change just before the last commit without losing the work done

# create one branch
git branch readDir

# move on this branch
git checkout readDir

# push
git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git readDir `

# back to the former branch
git checkout dev

# Revert the commit (number given on the terminal)
git revert d10a97d

# Push
git push

# Back to the branch
git checkout readDir

+DIVERSES COMMANDES+

To get status

git status

To get log

git log
git log --graph --pretty=format:'%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

Pour mettre la commande du dessus en alias dans git (exemple avec git lg) ` git config –global alias.lg “log –color –graph –pretty=format:’%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr) %C(bold blue)<%an>%Creset’ –abbrev-commit” `

git filter-branch --index-filter 'git rm --cached --ignore-unmatch DATA/expectedData/snpEffdata/MSU6.1/sequences.fa' --prune-empty --tag-name-filter cat -- --all

Docs:

https://ccwiki.in2p3.fr/developpements:formation:git http://www.moussu.fr/git/