Wiki » History » Version 10

Gateau, Thibault, 02/22/2019 03:34 PM

1 1 Gateau, Thibault
h1. 
2 1 Gateau, Thibault
Create local git repository and initialize it
3 1 Gateau, Thibault
4 2 Gateau, Thibault
h2. 
5 1 Gateau, Thibault
#create a local git server 
6 9 Gateau, Thibault
USER=charles
7 2 Gateau, Thibault
8 2 Gateau, Thibault
#T1>
9 1 Gateau, Thibault
cd && mkdir serverTestGit && cd serverTestGit
10 1 Gateau, Thibault
mkdir projet.git && cd projet.git
11 1 Gateau, Thibault
git --bare init
12 1 Gateau, Thibault
13 2 Gateau, Thibault
h2. 
14 1 Gateau, Thibault
#initialize it
15 2 Gateau, Thibault
16 2 Gateau, Thibault
#T2>
17 1 Gateau, Thibault
#cloner le repo pseudo-distant
18 1 Gateau, Thibault
cd && mkdir git && cd git
19 9 Gateau, Thibault
git clone ${USER}@localhost:~/serverTestGit/projet.git
20 7 Gateau, Thibault
cd projet
21 1 Gateau, Thibault
22 1 Gateau, Thibault
#configurer l'<user> local
23 9 Gateau, Thibault
git config --global user.email ${USER}@userplace.eu
24 9 Gateau, Thibault
git config --global user.name ${USER}
25 1 Gateau, Thibault
26 1 Gateau, Thibault
#faire un premier commit et le pusher
27 9 Gateau, Thibault
echo -e "lorem ispum \n titi \n toto" >> readme.md
28 1 Gateau, Thibault
git add readme.md
29 1 Gateau, Thibault
git commit -m "initial commit"
30 1 Gateau, Thibault
git push origin master
31 1 Gateau, Thibault
32 1 Gateau, Thibault
h2. 
33 1 Gateau, Thibault
#use it...
34 10 Gateau, Thibault
35 9 Gateau, Thibault
echo -e "another toto" >> readme.md
36 9 Gateau, Thibault
git add readme.md
37 9 Gateau, Thibault
git commit -m "my second commit"
38 9 Gateau, Thibault
git push origin master
39 9 Gateau, Thibault
echo -e "another titi" >> readme.md
40 9 Gateau, Thibault
git add readme.md
41 9 Gateau, Thibault
git commit -m "my third commit"
42 9 Gateau, Thibault
git push origin master
43 1 Gateau, Thibault
44 1 Gateau, Thibault
45 9 Gateau, Thibault
h2. 
46 9 Gateau, Thibault
#uses aliases
47 10 Gateau, Thibault
48 9 Gateau, Thibault
git lg1
49 9 Gateau, Thibault
wget https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/entry/.gitconfig
50 9 Gateau, Thibault
cp 
51 9 Gateau, Thibault
git config --global user.name ${USER}
52 9 Gateau, Thibault
git config --global user.email ${USER}@userplace.eu
53 1 Gateau, Thibault
54 9 Gateau, Thibault
h2. 
55 9 Gateau, Thibault
#conflict management
56 10 Gateau, Thibault
57 9 Gateau, Thibault
#T3> dans un autre terminal
58 9 Gateau, Thibault
#cloner le repo pseudo-distant
59 9 Gateau, Thibault
USER=bob
60 9 Gateau, Thibault
cd && mkdir gitBob && cd gitBob
61 9 Gateau, Thibault
git clone ${USER}@localhost:~/serverTestGit/projet.git
62 9 Gateau, Thibault
cd projet
63 9 Gateau, Thibault
git clone ${USER}@localhost:~/serverTestGit
64 9 Gateau, Thibault
cd serverTestGit
65 9 Gateau, Thibault
git config --local user.name ${USER}
66 9 Gateau, Thibault
echo -e "lorem ispum \n titi \n Bob \n toto" > readme.md
67 9 Gateau, Thibault
git add readme.md
68 9 Gateau, Thibault
git commit -m "I want to add my name in the file!"
69 9 Gateau, Thibault
#Et la on ne push pas...
70 9 Gateau, Thibault
git lg1
71 9 Gateau, Thibault
#* 199d358 - (3 seconds ago) I want to add my name in the file! - bob (HEAD, master)
72 9 Gateau, Thibault
#* 98c844b - (16 minutes ago) my third commit - charles (origin/master, origin/HEAD)
73 9 Gateau, Thibault
#* 327be69 - (16 minutes ago) my second commit - charles
74 9 Gateau, Thibault
#* 7562195 - (18 minutes ago) initial commit - charles
75 9 Gateau, Thibault
76 9 Gateau, Thibault
77 9 Gateau, Thibault
#T2> dans le terminal précédent:
78 10 Gateau, Thibault
79 9 Gateau, Thibault
cd && cd git
80 9 Gateau, Thibault
cd projet
81 9 Gateau, Thibault
USER=charles
82 9 Gateau, Thibault
git config --local user.name ${USER}
83 9 Gateau, Thibault
echo -e "lorem ispum \n titi \n Authors are us \n toto" > readme.md
84 9 Gateau, Thibault
git add readme.md
85 9 Gateau, Thibault
git commit -m "We should put our names in the file !"
86 9 Gateau, Thibault
#Et la on push comme avant
87 9 Gateau, Thibault
git push origin master
88 9 Gateau, Thibault
git lg1
89 9 Gateau, Thibault
#* 72f9bc3 - (4 seconds ago) We should put our names in the file ! - charles (HEAD, master)
90 9 Gateau, Thibault
#* 98c844b - (28 minutes ago) my third commit - charles
91 9 Gateau, Thibault
#* 327be69 - (28 minutes ago) my second commit - charles
92 9 Gateau, Thibault
#* 7562195 - (30 minutes ago) initial commit - charles
93 9 Gateau, Thibault
94 9 Gateau, Thibault
#T3> retour Terminal3
95 10 Gateau, Thibault
96 9 Gateau, Thibault
USER=bob
97 9 Gateau, Thibault
cd && cd gitBob/projet
98 9 Gateau, Thibault
git config --local user.name ${USER}
99 9 Gateau, Thibault
git push origin master
100 9 Gateau, Thibault
# ! [rejected]        master -> master (fetch first)
101 9 Gateau, Thibault
#error: failed to push some refs to '/home/charles/serverTestGit/projet.git/'
102 9 Gateau, Thibault
#hint: Updates were rejected because the remote contains work that you do
103 9 Gateau, Thibault
#hint: not have locally. This is usually caused by another repository pushing
104 9 Gateau, Thibault
#hint: to the same ref. You may want to first integrate the remote changes
105 9 Gateau, Thibault
#hint: (e.g., 'git pull ...') before pushing again.
106 9 Gateau, Thibault
#hint: See the 'Note about fast-forwards' in 'git push --help' for details.
107 9 Gateau, Thibault
108 9 Gateau, Thibault
git fetch #on récupère l'état du dépot distant
109 9 Gateau, Thibault
git lg1 #on constate qu'une branche est apparue !
110 9 Gateau, Thibault
#* 72f9bc3 - (36 minutes ago) We should put our names in the file ! - charles (origin/master, #origin/HEAD)
111 9 Gateau, Thibault
#| * 199d358 - (48 minutes ago) I want to add my name in the file! - bob (HEAD, master)
112 9 Gateau, Thibault
#|/  
113 9 Gateau, Thibault
#* 98c844b - (64 minutes ago) my third commit - charles
114 9 Gateau, Thibault
#* 327be69 - (64 minutes ago) my second commit - charles
115 9 Gateau, Thibault
#* 7562195 - (66 minutes ago) initial commit - charles
116 9 Gateau, Thibault
117 9 Gateau, Thibault
git checkout master #en fait, ici on y est déjà... mais les infos sont instructives !
118 9 Gateau, Thibault
#Already on 'master'
119 9 Gateau, Thibault
#Your branch and 'origin/master' have diverged,
120 9 Gateau, Thibault
#and have 1 and 1 different commit each, respectively.
121 9 Gateau, Thibault
#  (use "git pull" to merge the remote branch into yours)
122 9 Gateau, Thibault
#charles@port-charles-elitebook:~/gitBob/projet$ git lg1
123 9 Gateau, Thibault
124 9 Gateau, Thibault
git pull
125 9 Gateau, Thibault
#Auto-merging readme.md
126 9 Gateau, Thibault
#CONFLICT (content): Merge conflict in readme.md
127 9 Gateau, Thibault
#Automatic merge failed; fix conflicts and then commit the result.
128 9 Gateau, Thibault
129 9 Gateau, Thibault
#Et voila ! on a un conflit entre les 2 versions !
130 9 Gateau, Thibault
#pas de pannique: 
131 9 Gateau, Thibault
cat readme.md 
132 9 Gateau, Thibault
#lorem ispum 
133 9 Gateau, Thibault
# titi 
134 9 Gateau, Thibault
#<<<<<<< HEAD
135 9 Gateau, Thibault
# Bob 
136 9 Gateau, Thibault
#=======
137 9 Gateau, Thibault
# Authors are us 
138 9 Gateau, Thibault
#>>>>>>> 72f9bc327dc6bcbb76de5a1fb5c78f4195ac164c
139 9 Gateau, Thibault
# toto
140 9 Gateau, Thibault
141 9 Gateau, Thibault
#C'est plutôt clair... HEAD étant ma version (celle de Bob, et l'autre, la distante - remote - celle de Charles)
142 9 Gateau, Thibault
143 9 Gateau, Thibault
#2 solutions: 
144 9 Gateau, Thibault
#A la main : éditer readme.md, et le corriger
145 9 Gateau, Thibault
gedit readme.md
146 9 Gateau, Thibault
147 9 Gateau, Thibault
#Avec mergetool (meld par default) cf. https://gist.github.com/karenyyng/f19ff75c60f18b4b8149
148 9 Gateau, Thibault
#git mergetool
149 9 Gateau, Thibault
150 9 Gateau, Thibault
#et on a plus qu'a partager cet update (avec un nouveau commit)
151 9 Gateau, Thibault
git add readme.md
152 9 Gateau, Thibault
git ci -m "adding both authors is better after all"
153 9 Gateau, Thibault
git lg1
154 9 Gateau, Thibault
#*   878eb6a - (3 seconds ago) adding both authors is better after all - bob (HEAD, master)
155 9 Gateau, Thibault
#|\  
156 9 Gateau, Thibault
#| * 72f9bc3 - (53 minutes ago) We should put our names in the file ! - charles (origin/master, origin/HEAD)
157 9 Gateau, Thibault
#* | 199d358 - (64 minutes ago) I want to add my name in the file! - bob
158 9 Gateau, Thibault
#|/  
159 9 Gateau, Thibault
#* 98c844b - (80 minutes ago) my third commit - charles
160 9 Gateau, Thibault
#* 327be69 - (80 minutes ago) my second commit - charles
161 9 Gateau, Thibault
#* 7562195 - (82 minutes ago) initial commit - charles
162 9 Gateau, Thibault
git push origin master
163 9 Gateau, Thibault
164 9 Gateau, Thibault
#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 ! 
165 9 Gateau, Thibault
#git pull --rebase #au bon moment évidemment !
166 9 Gateau, Thibault
167 9 Gateau, Thibault
168 4 Gateau, Thibault
h1. 
169 4 Gateau, Thibault
Useful links
170 1 Gateau, Thibault
171 4 Gateau, Thibault
* example of .gitconfig: https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/entry/.gitconfig
172 5 Gateau, Thibault
* this readme.md: https://sourceforge.isae.fr/projects/iut_testing/repository/revisions/master/entry/localGitTutorial.md
173 4 Gateau, Thibault
* tutorials: 
174 4 Gateau, Thibault
   - official: https://git-scm.com/docs/gittutorial
175 4 Gateau, Thibault
   - interactive: https://www.katacoda.com/courses/git
176 3 Gateau, Thibault
   - branching interactive: https://learngitbranching.js.org/
177 3 Gateau, Thibault
   - smartgit: https://www.syntevo.com/smartgit/download/
178 9 Gateau, Thibault
   - conflict solving https://gist.github.com/karenyyng/f19ff75c60f18b4b8149