-
Notifications
You must be signed in to change notification settings - Fork 4
Git Beginner's Guide for Dummies
This page describes describes the main commands you need in order to use Git.
Authors | Christine Tranchant-Dubreuil |
---|---|
Research Unit | UMR DIADE |
Institut |
git
10/03/2017
- Download the repository using the
git clone
command - Update the downloaded repository using the
git pull
command - Add a file, commit and pull with
git add
,git commit
andgit pull
- Remove a file using
git rm
- Branching
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 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.
Don't forget to pull to download the latest changes before pushing
git add <filename>
git commit -m "message" <file name>
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
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
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.
git branch
[tranchant@master0 TOGGLE-ON-THE-FLY]$ git branch
* master
- indicates the branch used actually
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 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
git checkout <remote branch name>
git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git nom_branche_distante `
git branch <remote branch name>
git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git <remote branch name>
git checkout <remote branch name>
git checkout master
git pull https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master
git merge samtoolsBlock
You are responsible to merge those conflicts manually by editing the files shown by git status
.
git status
git commit -m "Branch merging samtoolsBlock-master" -a
git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git master `
git push https://github.com/SouthGreenPlatform/TOGGLE-DEV.git :nom_branche_a_suppr `
git branch nom-branche_a_suppr -d
# 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
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"
- pour virer un fichier du git quand il est trop gros (et qu'on ne peut plus pusher)
git filter-branch --index-filter 'git rm --cached --ignore-unmatch DATA/expectedData/snpEffdata/MSU6.1/sequences.fa' --prune-empty --tag-name-filter cat -- --all
https://ccwiki.in2p3.fr/developpements:formation:git http://www.moussu.fr/git/
The resource material is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/