Install git on windows https://gitforwindows.org
$ git config --global user.name "Pierre Navaro"
$ git config --global user.email "pierre.navaro@univ-rennes1.fr"
$ git config --global core.editor mvim
$ git config --global merge.tool opendiff
$ git config --list
user.name=Pierre Navaro
user.email=pierre.navaro@univ-rennes1.fr
core.editor=mvim
merge.tool=opendiff
Settings are saved on the computer for all your git repositories.
$ ls article
document.tex figure.png
$ git init
Initialized empty Git repository in /Users/navaro/article/.git/
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
document.tex
figure.png
nothing added to commit but untracked files present
(use "git add" to track)
$ git add document.tex
$ git add figure.png
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: document.tex
new file: figure.png
$ git commit -m 'Initial project version'}
[master (root-commit) 9d23b49] Initial project version
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 document.tex
create mode 100644 figure.png
$ git clone git@github.com:pnavaro/irmar-git-project.git
Cloning into 'projet'...
Initialized empty Git repository in /git/repositories/plm/navaro/projet.git/
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
$ cd sandbox/your_name
$ touch document.tex figure.png
$ git add document.tex figure.png
$ git commit -m 'Add my contribution to the project'
Your files are NOT present on the server!
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
By default you are on the “master” branch.
$ git branch
* master
Upload your files to the server:
$ git push origin master
...
To https://github.com/pnavaro/irmar-git-project
ae2ce3c..ed796ea master -> master
Now i change my computer.
$ git clone git@github.com:pnavaro/irmar-git-project.git
Cloning into 'irmar-git-project'...
$ cd irmar-git-project
$ git log
commit ed796ea1cbd15c8f7ec040b303c950569527012c (HEAD -> master, origin/master, origin/HEAD)
Author: Pierre Navaro <pierre.navaro@univ-rennes1.fr>
Date: Thu Apr 19 13:26:01 2018 +0200
Add my contribution to the project
Display all branches :
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
Create your own branch and switch:
$ git branch pierre-branch
$ git checkout pierre-branch
Switched to branch ‘pierre-branch’
$ git branch
master
* pierre-branch
Files could be different or non existant between branches but are at the same place on the file system
Modify the file document.tex
$ git status
On branch pierre-branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: document.tex
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/document.tex b/document.tex
index a608114..e69de29 100644
--- a/document.tex
+++ b/document.tex
@@ -1,3 +0,0 @@
-Exemple Git pour la journee de rentree
$ git add document.tex
Checking which files are ready to be committed.
$ git status
On branch pierre-branch
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: document.tex
Now save your work, the branch is local.
$ git commit -m 'Some modifications'
[pierre-branch 8c6bf81] Some modification is available
1 file changed, 3 insertions(+)
Use it carefully!
The master branch has changed. To get all new updates :
$ git checkout master
Switched to branch 'master'
$ git fetch origin
download changes from repository
$ git merge origin/master
update local branch master
$ git checkout pierre-branch
Switched to branch 'pierre-branch'
$ git merge master
update your branch
If you did not push your branch, use rebase
instead of merge
If you have conflict, no problem just do :
$ git mergetool
A nice editor helps you to choose the right version. Close and :
$ git commit -m 'Update and fixed conflicts'
Use itwhen you want to record the current state of the working directory and the index.
$ git stash
$ git stash show
git stash pop (or apply)
or drop them with
$ git stash drop
$ git diff --name-status master..mybranch
$ git diff mybranch master -- myfile.F90
$ git clean -xdf
$ git checkout myfile.cpp
$ git reset --hard