Create local git repository and initialize it¶
#create a local git server
USER=charles¶
#T1>
cd && mkdir serverTestGit && cd serverTestGit
mkdir projet.git && cd projet.git
git --bare init
#initialize it¶
#T2>
#cloner le repo pseudo-distant
cd && mkdir git && cd git
git clone ${USER}@localhost:~/serverTestGit/projet.git
cd projet
#configurer l'<user> local
git config --global user.email ${USER}@userplace.eu
git config --global user.name ${USER}
#faire un premier commit et le pusher
echo -e "lorem ispum \n titi \n toto" >> readme.md
git add readme.md
git commit -m "initial commit"
git push origin master
#use it...¶
echo -e "another toto" >> readme.md
git add readme.md
git commit -m "my second commit"
git push origin master
echo -e "another titi" >> readme.md
git add readme.md
git commit -m "my third commit"
git push origin master
#uses aliases¶
git lg1
wget https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/raw/.gitconfig
cp .gitconfig ~/.
git config --global user.name ${USER}
git config --global user.email ${USER}@userplace.eu
#conflict management¶
#T3> dans un autre terminal#cloner le repo pseudo-distant
USER=bob
cd && mkdir gitBob && cd gitBob
git clone ${USER}@localhost:~/serverTestGit/projet.git
cd projet
git clone ${USER}@localhost:~/serverTestGit
cd serverTestGit
git config --local user.name ${USER}
echo -e "lorem ispum \n titi \n Bob \n toto" > readme.md
git add readme.md
git commit -m "I want to add my name in the file!"
#Et la on ne push pas...
git lg1
- 199d358 - (3 seconds ago) I want to add my name in the file! - bob (HEAD, master)
- 98c844b - (16 minutes ago) my third commit - charles (origin/master, origin/HEAD)
- 327be69 - (16 minutes ago) my second commit - charles
- 7562195 - (18 minutes ago) initial commit - charles
#T2> dans le terminal précédent:
cd && cd gitcd projet
USER=charles
git config --local user.name ${USER}
echo -e "lorem ispum \n titi \n Authors are us \n toto" > readme.md
git add readme.md
git commit -m "We should put our names in the file !"
#Et la on push comme avant
git push origin master
git lg1
- 72f9bc3 - (4 seconds ago) We should put our names in the file ! - charles (HEAD, master)
- 98c844b - (28 minutes ago) my third commit - charles
- 327be69 - (28 minutes ago) my second commit - charles
- 7562195 - (30 minutes ago) initial commit - charles
#T3> retour Terminal3
USER=bobcd && cd gitBob/projet
git config --local user.name ${USER}
git push origin master
- ! [rejected] master -> master (fetch first)
#error: failed to push some refs to '/home/charles/serverTestGit/projet.git/'
#hint: Updates were rejected because the remote contains work that you do
#hint: not have locally. This is usually caused by another repository pushing
#hint: to the same ref. You may want to first integrate the remote changes
#hint: (e.g., 'git pull ...') before pushing again.
#hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git lg1 #on constate qu'une branche est apparue !
- 72f9bc3 - (36 minutes ago) We should put our names in the file ! - charles (origin/master, #origin/HEAD)
#| * 199d358 - (48 minutes ago) I want to add my name in the file! - bob (HEAD, master)
#|/ - 98c844b - (64 minutes ago) my third commit - charles
- 327be69 - (64 minutes ago) my second commit - charles
- 7562195 - (66 minutes ago) initial commit - charles
#Already on 'master'
#Your branch and 'origin/master' have diverged,
#and have 1 and 1 different commit each, respectively.
- (use "git pull" to merge the remote branch into yours)
#charles@port-charles-elitebook:~/gitBob/projet$ git lg1
git pull
#Auto-merging readme.md
#CONFLICT (content): Merge conflict in readme.md
#Automatic merge failed; fix conflicts and then commit the result.
#pas de pannique:
cat readme.md
#lorem ispum
- titi
#<<<<<<< HEAD - Bob #=======
- Authors are us
#>>>>>>> 72f9bc327dc6bcbb76de5a1fb5c78f4195ac164c - toto
#C'est plutôt clair... HEAD étant ma version (celle de Bob, et l'autre, la distante - remote - celle de Charles)
#2 solutions:
#A la main : éditer readme.md, et le corriger
gedit readme.md
#Avec mergetool (meld par default) cf. https://gist.github.com/karenyyng/f19ff75c60f18b4b8149
#git mergetool
git add readme.md
git ci -m "adding both authors is better after all"
git lg1
- 878eb6a - (3 seconds ago) adding both authors is better after all - bob (HEAD, master)
#|\
#| * 72f9bc3 - (53 minutes ago) We should put our names in the file ! - charles (origin/master, origin/HEAD) - | 199d358 - (64 minutes ago) I want to add my name in the file! - bob
#|/ - 98c844b - (80 minutes ago) my third commit - charles
- 327be69 - (80 minutes ago) my second commit - charles
- 7562195 - (82 minutes ago) initial commit - charles
git push origin master
#on note qu'une branche est apparue dans le projet. Pour éviter cela, on peut utiliser l'option --rebase lors du pull... à vous d'essayer !
#git pull --rebase #au bon moment évidemment !
Useful links¶
- example of .gitconfig: https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/entry/.gitconfig
- this readme.md: https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/entry/localGitTutorial.md
- tutorials:
- official: https://git-scm.com/docs/gittutorial
- interactive: https://www.katacoda.com/courses/git
- branching interactive: https://learngitbranching.js.org/
- smartgit: https://www.syntevo.com/smartgit/download/
- conflict solving https://gist.github.com/karenyyng/f19ff75c60f18b4b8149
h1.
Get all this stuff
sudo apt-get install --reinstall ca-certificates
git config --global http.sslverify false
git clone https://sourceforge.isae.fr/git/iut_testing