Child pages
  • Git

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Go to Stash → Create Project and call it "personal-<login>", replacing <login> with your own login name. Use your uppercase login name as project key, e.g. "MSP".
  2. Go to the Permissions tab of the project page and add the user "msp" as observer.
  3. On the project page, select Create Repository and name it "turing".
  4. Copy the SSH URL shown in the top right and email it to msp@informatik.uni-kiel.de. This will serve as proof for your work on this tutorial.
  5. Transfer your master branch to the new server-side repository. Replace the URL in the following command by the one copied from Stash:

    No Format
    $ git remote add stash ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
    $ git push stash 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)
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
     * [new branch]      master -> master

    The first command adds a remote named "stash" 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 Stash page in your browser, and you see all changes that are transferred to the server-side repository.

  6. Create a local clone of your remote repository (replace the URL accordingly):

    No Format
    $ cd ..
    $ git clone ssh://git@git.rtsys.informatik.uni-kiel.de:7999/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 named origin in the new local repository, which is set to the given URL. You will use this second clone to simulate another user with access to the repository.

  7. 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.
  8. 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)
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/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 = ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
    [branch "master"]
            remote = origin
            merge = refs/heads/master

    Here the branch master is linked with the remote origin, hence git push does the same as git push origin master.

  9. Go back to the original local repository and check out the master branch:

    No Format
    $ cd ../turing
    $ git checkout master
    Switched to branch 'master'
  10. Merge the sketches branch into master:

    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 diverged

  11. Fetch the server-side changes:

    No Format
    $ git fetch stash
    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 ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
       8af2d50..1d1577f  master     -> stash/master

    Now the change to examples.txt that was previously committed in the turing2 repository is stored in a remote tracking branch named stash/master:

    No Format
    $ git branch -a
    * master
      sketches
      remotes/stash/master

    You can analyze the remote tracking branch using the log and show commands. However, you should never directly modify a remote tracking branch.

  12. You can merge the remote changes into your local master branch with the following command:

    No Format
    $ git merge stash/master
    Auto-merging examples.txt
    Merge made by recursive.
     examples.txt |    8 ++++----
     1 files changed, 4 insertions(+), 4 deletions(-)

    Since this combination of fetch and merge is used very often, Git offers a shortcut for it, namely the pull command. In this case the according command would have been git pull stash master.

  13. Push the merged branch to the server, and then push the sketches branch, which is not on the server yet:

    No Format
    $ git push stash 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)
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
       1d1577f..957f686  master -> master
    $ git push stash sketches
    Total 0 (delta 0), reused 0 (delta 0)
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
     * [new branch]      sketches -> sketches
  14. As next step change your working directory to the second local repository turing2, add the following line to the end of notes.txt in the turing2 directory, and commit the change:

    No Format
    nopaneltrue
    TODO: formal definition
  15. Trying to push this commit to the server results in the following error message:

    No Format
    $ git push
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'ssh://git@git.rtsys.informatik.uni-kiel.de:personal-msp7999/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 for notes.txt.

  16. The solution is to apply the pull command followed by the push 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 ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
       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)
    To ssh://git@git.rtsys.informatik.uni-kiel.de:7999/MSP/turing.git
       957f686..b58ded7  master -> master

    While pull performs a fetch and a merge, 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. When used without parameters like shown above, pull lookes in .git/config to determine which branches to pull from which remotes.

  17. In order to check out the sketches branch locally, 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. Never check out origin/sketches, since that is a remote tracking branch!

...

No Format
$ git reset --hard
HEAD is now at b58ded7 Merge branch 'master' of git.rtsys.informatik.uni-kiel.de:personal-msp7999/MSP/turing

This resets all changes to the working copy to the head of the current branch, so use it with caution! However, reset does not remove unstaged files. In order to do that in one command, use clean:

...