Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
23.1 | 1 | This tutorial will address the source code management (SCM) tool named [[Git>>url:http://git-scm.com/||shape="rect"]]. By following these steps you should learn about the basic usage of Git, which is required for the whole practical course. Furthermore, Git is a great SCM tool, and it's good to know how to use it. During this tutorial, we will follow Alan Turing's thoughts towards developing the [[Turing Machine>>url:http://en.wikipedia.org/wiki/Turing_machine||shape="rect"]]. |
![]() |
1.1 | 2 | |
![]() |
28.1 | 3 | More in-depth documentation can be found on the [[official home page>>url:http://git-scm.com/documentation||shape="rect"]], which mentions books, videos, and links to other tutorials and references. |
![]() |
23.1 | 4 | |
![]() |
32.1 | 5 | ==== Contents ==== |
![]() |
31.1 | 6 | |
7 | |||
8 | |||
![]() |
32.1 | 9 | {{toc style="circle" maxLevel="3"/}} |
10 | |||
![]() |
24.1 | 11 | = Creating Commits = |
![]() |
1.1 | 12 | |
![]() |
23.1 | 13 | 1. Read the [[Git for Computer Scientists>>url:http://eagain.net/articles/git-for-computer-scientists/||shape="rect"]] introduction (skip this if you are already familiar with Git). |
14 | 1. For Linux, Git is available in its own package. Windows users can install [[msysGit>>url:http://msysgit.github.com/||shape="rect"]]. For MacOS, Git is available as part of [[Xcode>>url:https://developer.apple.com/xcode/||shape="rect"]]; if you cannot install that, use [[Git for OSX>>url:http://code.google.com/p/git-osx-installer/||shape="rect"]]. | ||
15 | 1. ((( | ||
![]() |
28.1 | 16 | Configure your name and email address (will be included in all commits you create): |
17 | |||
18 | {{noformat}} | ||
19 | $ git config --global --add user.name "Your Name" | ||
20 | $ git config --global --add user.email "<login>@informatik.uni-kiel.de" | ||
21 | {{/noformat}} | ||
22 | ))) | ||
23 | 1. ((( | ||
![]() |
23.1 | 24 | Create a local repository for the "//Turing Project//": |
![]() |
1.1 | 25 | |
![]() |
24.1 | 26 | {{noformat}} |
![]() |
23.1 | 27 | $ mkdir turing |
28 | $ cd turing | ||
29 | $ git init | ||
30 | Initialized empty Git repository in ~/turing/.git/ | ||
31 | {{/noformat}} | ||
![]() |
29.1 | 32 | |
33 | The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it. | ||
![]() |
23.1 | 34 | ))) |
35 | 1. ((( | ||
![]() |
27.1 | 36 | Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory. |
![]() |
1.1 | 37 | |
![]() |
24.1 | 38 | {{noformat}} |
![]() |
23.1 | 39 | $ git add notes.txt |
40 | $ git commit -m "wrote some first notes" | ||
41 | [master (root-commit) 2e73b34] wrote some first notes | ||
42 | 1 files changed, 5 insertions(+), 0 deletions(-) | ||
43 | create mode 100644 notes.txt | ||
44 | {{/noformat}} | ||
![]() |
29.1 | 45 | |
46 | The file is now stored in the local history of your repository. | ||
![]() |
23.1 | 47 | ))) |
![]() |
24.1 | 48 | 1. Edit {{code language="none"}}notes.txt{{/code}}:\\ |
49 | 11. Replace "fixed" with "infinite" in line 1. | ||
50 | 11. Replace "... (TODO)" with "a finite state machine" in line 4. | ||
51 | 1. ((( | ||
![]() |
27.1 | 52 | View the status of your current working copy: |
53 | |||
54 | {{noformat}} | ||
55 | $ git status | ||
56 | # On branch master | ||
57 | # Changed but not updated: | ||
58 | # (use "git add <file>..." to update what will be committed) | ||
59 | # (use "git checkout -- <file>..." to discard changes in working directory) | ||
60 | # | ||
61 | # modified: notes.txt | ||
62 | # | ||
63 | no changes added to commit (use "git add" and/or "git commit -a") | ||
64 | {{/noformat}} | ||
65 | ))) | ||
66 | 1. ((( | ||
67 | Mark the modified file to include it in the next commit, then view the status again and compare with the previous output: | ||
68 | |||
69 | {{noformat}} | ||
70 | $ git add notes.txt | ||
71 | $ git status | ||
72 | # On branch master | ||
73 | # Changes to be committed: | ||
74 | # (use "git reset HEAD <file>..." to unstage) | ||
75 | # | ||
76 | # modified: notes.txt | ||
77 | # | ||
78 | {{/noformat}} | ||
79 | ))) | ||
80 | 1. ((( | ||
![]() |
28.1 | 81 | Commit the modified content to your local repository and view the status: |
![]() |
24.1 | 82 | |
83 | {{noformat}} | ||
84 | $ git commit -m "modified tape length, found a controller for tape head" | ||
![]() |
27.1 | 85 | [master 52e2d49] modified tape length, found a controller for tape head |
![]() |
24.1 | 86 | 1 files changed, 2 insertions(+), 2 deletions(-) |
![]() |
28.1 | 87 | $ git status |
88 | # On branch master | ||
89 | nothing to commit (working directory clean) | ||
![]() |
24.1 | 90 | {{/noformat}} |
91 | ))) | ||
92 | |||
![]() |
26.1 | 93 | After the preceding steps you have two commits in your local repository, each with one file in the index. You have different commands for viewing these commits: |
![]() |
24.1 | 94 | |
95 | {{noformat}} | ||
96 | $ git log | ||
![]() |
27.1 | 97 | commit 52e2d4946791c2725015853e5e261ce143c6fe8a |
![]() |
24.1 | 98 | Author: Miro Spoenemann <msp@informatik.uni-kiel.de> |
![]() |
27.1 | 99 | Date: Mon Oct 15 15:00:14 2012 +0200 |
![]() |
24.1 | 100 | |
101 | modified tape length, found a controller for tape head | ||
102 | |||
103 | commit 2e73b34ac44480773fc0e52875b7353a087d8c6d | ||
104 | Author: Miro Spoenemann <msp@informatik.uni-kiel.de> | ||
105 | Date: Mon Oct 15 12:14:06 2012 +0200 | ||
106 | |||
107 | wrote some first notes | ||
108 | |||
![]() |
28.1 | 109 | $ git show 52e2d49 |
![]() |
27.1 | 110 | commit 52e2d4946791c2725015853e5e261ce143c6fe8a |
![]() |
24.1 | 111 | Author: Miro Spoenemann <msp@informatik.uni-kiel.de> |
![]() |
27.1 | 112 | Date: Mon Oct 15 15:00:14 2012 +0200 |
![]() |
24.1 | 113 | |
114 | modified tape length, found a controller for tape head | ||
115 | |||
116 | diff --git a/notes.txt b/notes.txt | ||
117 | index 4ded2b3..bd422b3 100644 | ||
118 | --- a/notes.txt | ||
119 | +++ b/notes.txt | ||
120 | @@ -1,5 +1,5 @@ | ||
121 | - * A tape with fixed length | ||
122 | + * A tape with infinite length | ||
123 | * Tape head can read or write data | ||
124 | * Tape head can move left or right | ||
125 | - * The head is controlled by ... (TODO) | ||
126 | + * The head is controlled by a finite state machine | ||
127 | {{/noformat}} | ||
128 | |||
![]() |
29.1 | 129 | Note that each commit is identified by a looong hash value, but it is possible to use only a prefix when referencing them (if the prefix is not ambiguous): the example above uses {{code language="none"}}52e2d49{{/code}} to identify the second commit. The commit hashes in your repository will be different from those seen in this tutorial, because the name of the author and the exact time of committing is also considered in the hash calculation. Also try the command {{code language="none"}}gitk{{/code}} to get an overview of your commits (a better alternative available for MacOS is [[GitX>>url:http://gitx.frim.nl/||shape="rect"]]). |
130 | |||
131 | = Branching and Merging = | ||
132 | |||
133 | In the previous section you have created two commits on the default branch, which is named {{code language="none"}}master{{/code}}. Now you will create a new branch and commit there, thus adding complexity to the commit graph. | ||
134 | |||
135 | 1. ((( | ||
136 | Create a branch with name //sketches//: | ||
137 | |||
138 | {{noformat}} | ||
139 | $ git branch sketches | ||
140 | {{/noformat}} | ||
141 | ))) | ||
142 | 1. ((( | ||
143 | View the list of branches: | ||
144 | |||
145 | {{noformat}} | ||
146 | $ git branch | ||
147 | * master | ||
148 | sketches | ||
149 | {{/noformat}} | ||
150 | |||
151 | The star reveals that you are still on the old {{code language="none"}}master{{/code}} branch. | ||
152 | ))) | ||
153 | 1. ((( | ||
154 | Switch to the new branch: | ||
155 | |||
156 | {{noformat}} | ||
157 | $ git checkout sketches | ||
158 | Switched to branch 'sketches' | ||
159 | $ git branch | ||
160 | master | ||
161 | * sketches | ||
162 | {{/noformat}} | ||
163 | |||
164 | It is also possible to create a branch and switch immediately to it using the option {{code language="none"}}-b{{/code}} of {{code language="none"}}git checkout{{/code}}. | ||
165 | ))) | ||
166 | 1. ((( | ||
![]() |
30.1 | 167 | Download and add the new file [[attach:examples.txt]]{{code language="none"}}{{/code}}: |
![]() |
29.1 | 168 | |
169 | {{noformat}} | ||
170 | $ git add examples.txt | ||
171 | $ git commit -m "wrote first examples" | ||
172 | [sketches cd63135] wrote first examples | ||
173 | 1 files changed, 20 insertions(+), 0 deletions(-) | ||
174 | create mode 100644 examples.txt | ||
175 | {{/noformat}} | ||
![]() |
30.1 | 176 | |
177 | Inspecting the commit graph with {{code language="none"}}gitk{{/code}} (or another graphical viewer) you see that the {{code language="none"}}sketches{{/code}} branch now has three commits, while {{code language="none"}}master{{/code}} is still at the second commit. | ||
![]() |
29.1 | 178 | ))) |
![]() |
30.1 | 179 | 1. ((( |
180 | Merging the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}} means that all changes that have been made in {{code language="none"}}sketches{{/code}} are also applied to {{code language="none"}}master{{/code}}. In order to perform this merge, we have to check out the {{code language="none"}}master{{/code}} branch first: | ||
181 | |||
182 | {{noformat}} | ||
183 | $ git checkout master | ||
184 | Switched to branch 'master' | ||
185 | $ git merge sketches | ||
186 | Updating 52e2d49..cd63135 | ||
187 | Fast-forward | ||
188 | examples.txt | 20 ++++++++++++++++++++ | ||
189 | 1 files changed, 20 insertions(+), 0 deletions(-) | ||
190 | create mode 100644 examples.txt | ||
191 | {{/noformat}} | ||
192 | |||
193 | This was a //fast-forward// merge: since the {{code language="none"}}master{{/code}} branch was completely contained in the {{code language="none"}}sketches{{/code}} branch, the merge could be done by simply changing the head pointer of {{code language="none"}}master{{/code}} to be the same as the head of {{code language="none"}}sketches{{/code}}. | ||
194 | ))) | ||
195 | 1. ((( | ||
196 | Now add the line "{{code language="none"}}see some examples in 'examples.txt'{{/code}}" to the file {{code language="none"}}notes.txt{{/code}} and commit this change in the current branch: | ||
197 | |||
198 | {{noformat}} | ||
199 | $ git add notes.txt | ||
200 | $ git commit -m "added reference to the new examples" | ||
201 | [master a5e244f] added reference to the new examples | ||
202 | 1 files changed, 2 insertions(+), 1 deletions(-) | ||
203 | {{/noformat}} | ||
204 | ))) | ||
205 | 1. ((( | ||
206 | Switch back to the {{code language="none"}}sketches{{/code}} branch and commit something there. Note that the {{code language="none"}}checkout{{/code}} command modifies your working copy, hence you have to update your text editor's content if you opened one of the files. | ||
207 | |||
208 | {{noformat}} | ||
209 | $ git checkout sketches | ||
210 | Switched to branch 'sketches' | ||
211 | {{/noformat}} | ||
212 | |||
213 | Add the line "{{code language="none"}}Move one step left:{{/code}}" and write an updated version of the tape with tape head in the file {{code language="none"}}examples.txt{{/code}}, then commit. | ||
214 | |||
215 | {{noformat}} | ||
216 | $ git add examples.txt | ||
217 | $ git commit -m "added another example" | ||
218 | [sketches 55a9cb1] added another example | ||
219 | 1 files changed, 5 insertions(+), 0 deletions(-) | ||
220 | {{/noformat}} | ||
221 | |||
222 | Now our two branches have //diverged//, which means that they cannot be fast-forwarded anymore. | ||
223 | ))) | ||
224 | 1. ((( | ||
225 | Merge the {{code language="none"}}master{{/code}} branch into {{code language="none"}}sketches{{/code}}: | ||
226 | |||
227 | {{noformat}} | ||
228 | $ git merge master | ||
229 | Merge made by recursive. | ||
230 | notes.txt | 3 ++- | ||
231 | 1 files changed, 2 insertions(+), 1 deletions(-) | ||
232 | {{/noformat}} | ||
233 | |||
234 | Using {{code language="none"}}gitk{{/code}} you can see that a new commit was created that has two parent commits. Such a commit is called //merge// commit and is done automatically when a non-fast-forward merge is applied. | ||
235 | ))) | ||
236 | 1. ((( | ||
237 | Add a commit in each of the two branches using the commands you have already learned. | ||
238 | 1. Check out {{code language="none"}}master{{/code}}. | ||
239 | 1. ((( | ||
240 | Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}: | ||
241 | |||
242 | {{noformat nopanel="true"}} | ||
243 | * The finite state machine has an initial state and one or more final states | ||
244 | {{/noformat}} | ||
245 | ))) | ||
246 | 1. Commit the change to {{code language="none"}}notes.txt{{/code}}. | ||
247 | 1. Check out {{code language="none"}}sketches{{/code}} (make sure to refresh your text editor so {{code language="none"}}notes.txt{{/code}} is reset to its previous state, without the change made above). | ||
248 | 1. ((( | ||
249 | Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}: | ||
250 | |||
251 | {{noformat nopanel="true"}} | ||
252 | * Each state transition can trigger head movement and data read/write | ||
253 | {{/noformat}} | ||
254 | ))) | ||
255 | 1. Commit the change to {{code language="none"}}notes.txt{{/code}}. | ||
256 | ))) | ||
257 | 1. ((( | ||
258 | Merge the {{code language="none"}}master{{/code}} branch into the current branch ({{code language="none"}}sketches{{/code}}): | ||
259 | |||
260 | {{noformat}} | ||
261 | $ git merge master | ||
262 | Auto-merging notes.txt | ||
263 | CONFLICT (content): Merge conflict in notes.txt | ||
264 | Automatic merge failed; fix conflicts and then commit the result. | ||
265 | {{/noformat}} | ||
266 | |||
267 | As expected, the branches could not be merged automatically, since both branches modified the same line in the same file. | ||
268 | ))) | ||
269 | 1. ((( | ||
270 | Use the {{code language="none"}}status{{/code}} command to see the list of affected files: | ||
271 | |||
272 | {{noformat}} | ||
273 | $ git status | ||
274 | # On branch sketches | ||
275 | # Unmerged paths: | ||
276 | # (use "git add/rm <file>..." as appropriate to mark resolution) | ||
277 | # | ||
278 | # both modified: notes.txt | ||
279 | # | ||
280 | no changes added to commit (use "git add" and/or "git commit -a") | ||
281 | {{/noformat}} | ||
282 | ))) | ||
283 | 1. ((( | ||
284 | The modified {{code language="none"}}notes.txt{{/code}} should now contain the following text: | ||
285 | |||
286 | {{noformat nopanel="true"}} | ||
287 | <<<<<<< HEAD | ||
288 | * Each state transition can trigger head movement and data read/write | ||
289 | ======= | ||
290 | * The finite state machine has an initial state and one or more final states | ||
291 | >>>>>>> master | ||
292 | {{/noformat}} | ||
293 | |||
294 | The upper line is the one committed to {{code language="none"}}sketches{{/code}}, while the lower line was committed to {{code language="none"}}master{{/code}}. You have to resolve the conflict by editing the file. In this case the conflict is resolved by keeping both lines in arbitrary order, that means you should just remove the conflict markers (lines 5, 7, and 9 in {{code language="none"}}notes.txt{{/code}}). | ||
295 | ))) | ||
296 | 1. ((( | ||
297 | Use the {{code language="none"}}add{{/code}} command to mark {{code language="none"}}notes.txt{{/code}} as resolved. Entering {{code language="none"}}git commit{{/code}} without a message will open a text editor with an automatically created commit message. Just close the editor, and the merge commit is completed: | ||
298 | |||
299 | {{noformat}} | ||
300 | $ git commit | ||
301 | [sketches 21d5ddb] Merge branch 'master' into sketches | ||
302 | $ git show 21d5ddb | ||
303 | commit 21d5ddbbcba4e36464653a2a550dbf595ead921f | ||
304 | Merge: 17f75c7 8af2d50 | ||
305 | Author: Miro Spoenemann <msp@informatik.uni-kiel.de> | ||
306 | Date: Tue Oct 16 10:44:09 2012 +0200 | ||
307 | |||
308 | Merge branch 'master' into sketches | ||
309 | |||
310 | Conflicts: | ||
311 | notes.txt | ||
312 | |||
313 | diff --cc notes.txt | ||
314 | index 8f72873,bb81298..ba94a08 | ||
315 | --- a/notes.txt | ||
316 | +++ b/notes.txt | ||
317 | @@@ -2,6 -2,6 +2,7 @@@ | ||
318 | * Tape head can read or write data | ||
319 | * Tape head can move left or right | ||
320 | * The head is controlled by a finite state machine | ||
321 | + * Each state transition can trigger head movement and data read/write | ||
322 | + * The finite state machine has an initial state and one or more final states | ||
323 | see some examples in 'examples.txt' | ||
324 | {{/noformat}} | ||
325 | ))) | ||
326 | |||
327 | The {{code language="none"}}gitk{{/code}} tool should now display this graph: | ||
328 | |||
329 | [[image:attach:turing-graph-01.png]] | ||
330 | |||
![]() |
33.1 | 331 | = Remote Repositories = |
332 | |||
333 | In the previous sections you have worked only with a local repository. The next step is to share this content with a remote repository. Later we will use [[Stash>>url:https://www.atlassian.com/software/stash/overview||shape="rect"]] for repository management, but we need to create group accounts for you first, thus you will use another system called [[Gitorious>>url:https://git.rtsys.informatik.uni-kiel.de/||shape="rect"]] for now. | ||
334 | |||
335 | 1. Register to the Gitorious system: [[https:~~/~~/git.rtsys.informatik.uni-kiel.de/>>url:https://git.rtsys.informatik.uni-kiel.de/||shape="rect"]] (use your //Institut für Informatik// login name and email address) | ||
336 | 1. Go to your //Dashboard// → //Manage SSH keys// → //Add SSH key// | ||
337 | 1. Copy & paste the content of your public SSH key.\\ | ||
338 | 1*. If you don't have an SSH key: use the shell command {{code language="none"}}ssh-keygen{{/code}}, confirm the default destination file {{code language="none"}}~/.ssh/id_rsa{{/code}}, and choose whether to give a passphrase. If you have a passphrase, you need to enter it whenever you use your SSH key for the first time in a session. You can omit the passphrase, but that makes the key less secure. As result, the tool generates a private key {{code language="none"}}~/.ssh/id_rsa{{/code}}, which has to be kept secret, and a public key {{code language="none"}}~/.ssh/id_rsa.pub{{/code}}. | ||
![]() |
34.1 | 339 | 1. Go to //Projects// → //Create a new project// and call it "personal-<login>", replacing <login> with your own login name. |
![]() |
33.1 | 340 | 1. On the next page, create a repository named "turing" (or select //Add repository// on your project page). |
341 | 1. Once you are on the repository page, copy the URL shown in //Clone & push urls//. | ||
![]() |
34.1 | 342 | 1. ((( |
343 | Transfer your {{code language="none"}}master{{/code}} branch to the new server-side repository. Replace the URL in the following command by the one copied from Gitorious: | ||
344 | |||
345 | {{noformat}} | ||
346 | $ git remote add gitorious git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
347 | $ git push gitorious master | ||
348 | Counting objects: 15, done. | ||
349 | Delta compression using up to 16 threads. | ||
350 | Compressing objects: 100% (13/13), done. | ||
351 | Writing objects: 100% (15/15), 1.54 KiB, done. | ||
352 | Total 15 (delta 3), reused 0 (delta 0) | ||
353 | remote: => Syncing Gitorious... [OK] | ||
354 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
355 | * [new branch] master -> master | ||
356 | {{/noformat}} | ||
357 | |||
358 | The first command adds a //remote// named "gitorious" to your local repository, which is just a bookmark for the long URL. The second command transfers the {{code language="none"}}master{{/code}} branch to the server, which is called //pushing//. After that is done, reload the Gitorious page in your browser, and you see all changes that are transferred to the server-side repository. | ||
359 | ))) | ||
360 | 1. ((( | ||
361 | Create a local clone of your remote repository (replace the URL accordingly): | ||
362 | |||
363 | {{noformat}} | ||
364 | $ cd .. | ||
365 | $ git clone git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git turing2 | ||
366 | Initialized empty Git repository in /home/msp/tmp/turing2/.git/ | ||
367 | remote: Counting objects: 15, done. | ||
368 | remote: Compressing objects: 100% (13/13), done. | ||
369 | remote: Total 15 (delta 3), reused 0 (delta 0) | ||
370 | Receiving objects: 100% (15/15), done. | ||
371 | Resolving deltas: 100% (3/3), done. | ||
372 | $ cd turing2 | ||
373 | {{/noformat}} | ||
374 | |||
375 | The {{code language="none"}}clone{{/code}} command automatically creates a remote named {{code language="none"}}origin{{/code}} in the new local repository, which is set to the given URL. | ||
376 | ))) | ||
377 | 1. Edit the file {{code language="none"}}examples.txt{{/code}} in the new clone ({{code language="none"}}turing2{{/code}}): replace {{code language="none"}}"a"{{/code}} in line 6 by {{code language="none"}}"c"{{/code}} and correct the tape representations in lines 9, 14, and 19 accordingly. Commit the change. | ||
378 | 1. ((( | ||
379 | Push the new commit to the server: | ||
380 | |||
381 | {{noformat}} | ||
382 | $ git push | ||
383 | Counting objects: 5, done. | ||
384 | Delta compression using up to 16 threads. | ||
385 | Compressing objects: 100% (3/3), done. | ||
386 | Writing objects: 100% (3/3), 362 bytes, done. | ||
387 | Total 3 (delta 1), reused 0 (delta 0) | ||
388 | remote: => Syncing Gitorious... [OK] | ||
389 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
390 | 8af2d50..1d1577f master -> master | ||
391 | {{/noformat}} | ||
392 | |||
393 | In this case the push command can be used without arguments, which means that it pushes all branches as configured in {{code language="none"}}.git/config{{/code}}: | ||
394 | |||
395 | {{noformat}} | ||
396 | $ more .git/config | ||
397 | [core] | ||
398 | repositoryformatversion = 0 | ||
399 | filemode = true | ||
400 | bare = false | ||
401 | logallrefupdates = true | ||
402 | [remote "origin"] | ||
403 | fetch = +refs/heads/*:refs/remotes/origin/* | ||
404 | url = git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
405 | [branch "master"] | ||
406 | remote = origin | ||
407 | merge = refs/heads/master | ||
408 | {{/noformat}} | ||
409 | |||
410 | Here the branch {{code language="none"}}master{{/code}} is linked with the remote {{code language="none"}}origin{{/code}}, hence {{code language="none"}}git push{{/code}} does the same as {{code language="none"}}git push origin master{{/code}}. | ||
411 | ))) | ||
412 | 1. ((( | ||
413 | Go back to the original local repository and check out the {{code language="none"}}master{{/code}} branch: | ||
414 | |||
415 | {{noformat}} | ||
416 | $ cd ../turing | ||
417 | $ git checkout master | ||
418 | Switched to branch 'master' | ||
419 | {{/noformat}} | ||
420 | ))) | ||
421 | 1. ((( | ||
422 | Merge the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}}: | ||
423 | |||
424 | {{noformat}} | ||
425 | $ git merge sketches | ||
426 | Updating 8af2d50..21d5ddb | ||
427 | Fast-forward | ||
428 | examples.txt | 5 +++++ | ||
429 | notes.txt | 1 + | ||
430 | 2 files changed, 6 insertions(+), 0 deletions(-) | ||
431 | {{/noformat}} | ||
432 | |||
433 | Now your local {{code language="none"}}master{{/code}} branch and the one on the server-side repository have diverged | ||
434 | ))) | ||
435 | 1. ((( | ||
436 | Fetch the server-side changes: | ||
437 | |||
438 | {{noformat}} | ||
439 | $ git fetch gitorious | ||
440 | remote: Counting objects: 5, done. | ||
441 | remote: Compressing objects: 100% (3/3), done. | ||
442 | remote: Total 3 (delta 1), reused 0 (delta 0) | ||
443 | Unpacking objects: 100% (3/3), done. | ||
444 | From git.rtsys.informatik.uni-kiel.de:personal-msp/turing | ||
445 | 8af2d50..1d1577f master -> gitorious/master | ||
446 | {{/noformat}} | ||
447 | |||
448 | Now the change to {{code language="none"}}examples.txt{{/code}} that was previously committed in the {{code language="none"}}turing2{{/code}} repository is stored in a //remote tracking branch// named {{code language="none"}}gitorious/master{{/code}}: | ||
449 | |||
450 | {{noformat}} | ||
451 | $ git branch -a | ||
452 | * master | ||
453 | sketches | ||
454 | remotes/gitorious/master | ||
455 | {{/noformat}} | ||
456 | |||
457 | You can analyze the remote tracking branch using the {{code language="none"}}log{{/code}} and {{code language="none"}}show{{/code}} commands. However, you should never directly modify a remote tracking branch. | ||
458 | ))) | ||
459 | 1. ((( | ||
460 | You can merge the remote changes into your local {{code language="none"}}master{{/code}} branch with the following command: | ||
461 | |||
462 | {{noformat}} | ||
463 | $ git merge gitorious/master | ||
464 | Auto-merging examples.txt | ||
465 | Merge made by recursive. | ||
466 | examples.txt | 8 ++++---- | ||
467 | 1 files changed, 4 insertions(+), 4 deletions(-) | ||
468 | {{/noformat}} | ||
469 | |||
470 | Since this combination of {{code language="none"}}fetch{{/code}} and {{code language="none"}}merge{{/code}} is used very often, Git offers a shortcut for it, namely the {{code language="none"}}pull{{/code}} command. In this case the according command would have been {{code language="none"}}git pull gitorious master{{/code}}. | ||
471 | ))) | ||
472 | 1. ((( | ||
473 | Push the merged branch to the server, and then push the {{code language="none"}}sketches{{/code}} branch, which is not on the server yet: | ||
474 | |||
475 | {{noformat}} | ||
476 | $ git push gitorious master | ||
477 | Counting objects: 23, done. | ||
478 | Delta compression using up to 16 threads. | ||
479 | Compressing objects: 100% (14/14), done. | ||
480 | Writing objects: 100% (14/14), 1.65 KiB, done. | ||
481 | Total 14 (delta 4), reused 0 (delta 0) | ||
482 | remote: => Syncing Gitorious... [OK] | ||
483 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
484 | 1d1577f..957f686 master -> master | ||
485 | $ git push gitorious sketches | ||
486 | Total 0 (delta 0), reused 0 (delta 0) | ||
487 | remote: => Syncing Gitorious... [OK] | ||
488 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
489 | * [new branch] sketches -> sketches | ||
490 | {{/noformat}} | ||
491 | ))) | ||
492 | 1. ((( | ||
493 | As next step change your working directory to the second local repository {{code language="none"}}turing2{{/code}}, add the following line to the end of {{code language="none"}}notes.txt{{/code}} in the {{code language="none"}}turing2{{/code}} directory, and commit the change: | ||
494 | |||
495 | {{noformat nopanel="true"}} | ||
496 | TODO: formal definition | ||
497 | {{/noformat}} | ||
498 | ))) | ||
499 | 1. ((( | ||
500 | Trying to push this commit to the server results in the following error message: | ||
501 | |||
502 | {{noformat}} | ||
503 | $ git push | ||
504 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
505 | ! [rejected] master -> master (non-fast-forward) | ||
506 | error: failed to push some refs to 'git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git' | ||
507 | To prevent you from losing history, non-fast-forward updates were rejected | ||
508 | Merge the remote changes before pushing again. See the 'Note about | ||
509 | fast-forwards' section of 'git push --help' for details. | ||
510 | {{/noformat}} | ||
511 | |||
512 | This is because you have modified the branch while working in the original {{code language="none"}}turing{{/code}} repository, and these changes have to be merged with the new commit you have just made for {{code language="none"}}notes.txt{{/code}}. | ||
513 | ))) | ||
514 | 1. ((( | ||
515 | The solution is to apply the {{code language="none"}}pull{{/code}} command followed by the {{code language="none"}}push{{/code}} command: | ||
516 | |||
517 | {{noformat}} | ||
518 | $ git pull | ||
519 | remote: Counting objects: 23, done. | ||
520 | remote: Compressing objects: 100% (14/14), done. | ||
521 | remote: Total 14 (delta 4), reused 0 (delta 0) | ||
522 | Unpacking objects: 100% (14/14), done. | ||
523 | From git.rtsys.informatik.uni-kiel.de:personal-msp/turing | ||
524 | 1d1577f..957f686 master -> origin/master | ||
525 | * [new branch] sketches -> origin/sketches | ||
526 | Auto-merging notes.txt | ||
527 | Merge made by recursive. | ||
528 | examples.txt | 5 +++++ | ||
529 | notes.txt | 1 + | ||
530 | 2 files changed, 6 insertions(+), 0 deletions(-) | ||
531 | $ git push | ||
532 | Counting objects: 10, done. | ||
533 | Delta compression using up to 16 threads. | ||
534 | Compressing objects: 100% (6/6), done. | ||
535 | Writing objects: 100% (6/6), 673 bytes, done. | ||
536 | Total 6 (delta 2), reused 0 (delta 0) | ||
537 | remote: => Syncing Gitorious... [OK] | ||
538 | To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git | ||
539 | 957f686..b58ded7 master -> master | ||
540 | {{/noformat}} | ||
541 | |||
542 | While {{code language="none"}}pull{{/code}} performs a {{code language="none"}}fetch{{/code}} and a {{code language="none"}}merge{{/code}}, {{code language="none"}}push{{/code}} transfers the new merged branch to the server. Note that during the merge operation conflicts can occur. In that case you have to resolve them and commit the changes before you can push. | ||
543 | ))) | ||
544 | 1. ((( | ||
545 | In order to check out the {{code language="none"}}sketches{{/code}} branch, which was previously pushed to the server, simply type the following command: | ||
546 | |||
547 | {{noformat}} | ||
548 | $ git checkout sketches | ||
549 | Branch sketches set up to track remote branch sketches from origin. | ||
550 | Switched to a new branch 'sketches' | ||
551 | {{/noformat}} | ||
552 | |||
553 | This branch can be pushed and pulled with the server in the same way as you did for the {{code language="none"}}master{{/code}} branch. | ||
554 | ))) | ||
555 | |||
556 | The {{code language="none"}}master{{/code}} branch should look like this: | ||
557 | |||
558 | [[image:attach:turing-graph-02.png]] | ||
559 | |||
560 |