...
More in-depth documentation can be found on the official home page, which mentions books, videos, and links to other tutorials and references. Furthermore, the shell command git help
lists the most commonly used Git commands, and git help <command>
gives very detailed documentation for the specified Git command.
Contents
Table of Contents | ||||
---|---|---|---|---|
|
...
- Register to the Gitorious system: https://git.rtsys.informatik.uni-kiel.de/ (use your Institut für Informatik login name and email address)
- Go to your Dashboard → Manage SSH keys → Add SSH key
- Copy & paste the content of your public SSH key.
- If you don't have an SSH key: use the shell command
ssh-keygen
, confirm the default destination file~/.ssh/id_rsa
, 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~/.ssh/id_rsa
, which has to be kept secret, and a public key~/.ssh/id_rsa.pub
.
- If you don't have an SSH key: use the shell command
- Go to Projects → Create a new project and call it "personal-<login>", replacing <login> with your own login name.
- On the next page, create a repository named "turing" (or select Add repository on your project page).
- Once you are on the repository page, copy the URL shown in Clone & push urls.
- Email the copied URL to msp@informatik.uni-kiel.de. This will serve as proof for your work on this tutorial.
Transfer your
master
branch to the new server-side repository. Replace the URL in the following command by the one copied from Gitorious:No Format $ git remote add gitorious git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git $ git push gitorious master Counting objects: 15, done. Delta compression using up to 16 threads. Compressing objects: 100% (13/13), done. Writing objects: 100% (15/15), 1.54 KiB, done. Total 15 (delta 3), reused 0 (delta 0) remote: => Syncing Gitorious... [OK] To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git * [new branch] master -> master
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
master
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.Create a local clone of your remote repository (replace the URL accordingly):
No Format $ cd .. $ git clone git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git turing2 Initialized empty Git repository in /home/msp/tmp/turing2/.git/ remote: Counting objects: 15, done. remote: Compressing objects: 100% (13/13), done. remote: Total 15 (delta 3), reused 0 (delta 0) Receiving objects: 100% (15/15), done. Resolving deltas: 100% (3/3), done. $ cd turing2
The
clone
command automatically creates a remote namedorigin
in the new local repository, which is set to the given URL.- Edit the file
examples.txt
in the new clone (turing2
): replace"a"
in line 6 by"c"
and correct the tape representations in lines 9, 14, and 19 accordingly. Commit the change. Push the new commit to the server:
No Format $ git push Counting objects: 5, done. Delta compression using up to 16 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 362 bytes, done. Total 3 (delta 1), reused 0 (delta 0) remote: => Syncing Gitorious... [OK] To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git 8af2d50..1d1577f master -> master
In this case the push command can be used without arguments, which means that it pushes all branches as configured in
.git/config
:No Format $ more .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git [branch "master"] remote = origin merge = refs/heads/master
Here the branch
master
is linked with the remoteorigin
, hencegit push
does the same asgit push origin master
.Go back to the original local repository and check out the
master
branch:No Format $ cd ../turing $ git checkout master Switched to branch 'master'
Merge the
sketches
branch intomaster
:No Format $ git merge sketches Updating 8af2d50..21d5ddb Fast-forward examples.txt | 5 +++++ notes.txt | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
Now your local
master
branch and the one on the server-side repository have divergedFetch the server-side changes:
No Format $ git fetch gitorious remote: Counting objects: 5, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From git.rtsys.informatik.uni-kiel.de:personal-msp/turing 8af2d50..1d1577f master -> gitorious/master
Now the change to
examples.txt
that was previously committed in theturing2
repository is stored in a remote tracking branch namedgitorious/master
:No Format $ git branch -a * master sketches remotes/gitorious/master
You can analyze the remote tracking branch using the
log
andshow
commands. However, you should never directly modify a remote tracking branch.You can merge the remote changes into your local
master
branch with the following command:No Format $ git merge gitorious/master Auto-merging examples.txt Merge made by recursive. examples.txt | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
Since this combination of
fetch
andmerge
is used very often, Git offers a shortcut for it, namely thepull
command. In this case the according command would have beengit pull gitorious master
.Push the merged branch to the server, and then push the
sketches
branch, which is not on the server yet:No Format $ git push gitorious master Counting objects: 23, done. Delta compression using up to 16 threads. Compressing objects: 100% (14/14), done. Writing objects: 100% (14/14), 1.65 KiB, done. Total 14 (delta 4), reused 0 (delta 0) remote: => Syncing Gitorious... [OK] To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git 1d1577f..957f686 master -> master $ git push gitorious sketches Total 0 (delta 0), reused 0 (delta 0) remote: => Syncing Gitorious... [OK] To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git * [new branch] sketches -> sketches
As next step change your working directory to the second local repository
turing2
, add the following line to the end ofnotes.txt
in theturing2
directory, and commit the change:No Format nopanel true TODO: formal definition
Trying to push this commit to the server results in the following error message:
No Format $ git push To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
This is because you have modified the branch while working in the original
turing
repository, and these changes have to be merged with the new commit you have just made fornotes.txt
.The solution is to apply the
pull
command followed by thepush
command:No Format $ git pull remote: Counting objects: 23, done. remote: Compressing objects: 100% (14/14), done. remote: Total 14 (delta 4), reused 0 (delta 0) Unpacking objects: 100% (14/14), done. From git.rtsys.informatik.uni-kiel.de:personal-msp/turing 1d1577f..957f686 master -> origin/master * [new branch] sketches -> origin/sketches Auto-merging notes.txt Merge made by recursive. examples.txt | 5 +++++ notes.txt | 1 + 2 files changed, 6 insertions(+), 0 deletions(-) $ git push Counting objects: 10, done. Delta compression using up to 16 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 673 bytes, done. Total 6 (delta 2), reused 0 (delta 0) remote: => Syncing Gitorious... [OK] To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git 957f686..b58ded7 master -> master
While
pull
performs afetch
and amerge
,push
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.In order to check out the
sketches
branch, which was previously pushed to the server, simply type the following command:No Format $ git checkout sketches Branch sketches set up to track remote branch sketches from origin. Switched to a new branch 'sketches'
This branch can be pushed and pulled with the server in the same way as you did for the
master
branch.
...