...
- Read the Git for Computer Scientists introduction (skip this if you are already familiar with Git).
- For Linux, Git is available in its own package. Windows users can install msysGit. For MacOS, Git is available as part of Xcode; if you cannot install that, use Git for OSX.
Configure your name and email address (will be included in all commits you create):
No Format $ git config --global --add user.name "Your Name" $ git config --global --add user.email "<login>@informatik.uni-kiel.de"
Create a local repository for the "Turing Project":
No Format $ mkdir turing $ cd turing $ git init Initialized empty Git repository in ~/turing/.git/
The
.git
subdirectory contains all history and metadata of the repository. You should not modify it.Add and commit some content: copy
notes.txt
to yourturing
directory.No Format $ git add notes.txt $ git commit -m "wrote some first notes" [master (root-commit) 2e73b34] wrote some first notes 1 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 notes.txt
The file is now stored in the local history of your repository.
- Edit
notes.txt
:- Replace "fixed" with "infinite" in line 1.
- Replace "... (TODO)" with "a finite state machine" in line 4.
View the status of your current working copy:
No Format $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: notes.txt # no changes added to commit (use "git add" and/or "git commit -a")
Mark the modified file to include it in the next commit, then view the status again and compare with the previous output:
No Format $ git add notes.txt $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: notes.txt #
Commit the modified content to your local repository and view the status:
No Format $ git commit -m "modified tape length, found a controller for tape head" [master 52e2d49] modified tape length, found a controller for tape head 1 files changed, 2 insertions(+), 2 deletions(-) $ git status # On branch master nothing to commit (working directory clean)
...
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 52e2d49
to identify the second commit. Also try the command gitk
to get an overview of your commits (a better alternative available for MacOS is GitX). The 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 gitk
to get an overview of your commits (a better alternative available for MacOS is GitX).
Branching and Merging
In the previous section you have created two commits on the default branch, which is named master
. Now you will create a new branch and commit there, thus adding complexity to the commit graph.
Create a branch with name sketches:
No Format $ git branch sketches
View the list of branches:
No Format $ git branch * master sketches
The star reveals that you are still on the old
master
branch.Switch to the new branch:
No Format $ git checkout sketches Switched to branch 'sketches' $ git branch master * sketches
It is also possible to create a branch and switch immediately to it using the option
-b
ofgit checkout
.Add the new file examples.txt:
No Format $ git add examples.txt $ git commit -m "wrote first examples" [sketches cd63135] wrote first examples 1 files changed, 20 insertions(+), 0 deletions(-) create mode 100644 examples.txt