Writing code is collaborative and requires large amounts of editing sometimes at a blistering pace, naturally a number of problems arise as a result of this and for those problems we have source control.
Git is a program that provides source control originally written Linus Torvalds to replace the controversial use of BitKeeper in the development of Linux. Other than Git, you may also encounter Subversion on occasion.
- Work through Learn Enough Git to Be Dangerous
- Test your knowledge by working through the exercises below
Stop and Understand
What is the purpose of source control?
How does Git differ from other source control tools?
Explain the Git tree visually
Draw a Git tree that has 8 commits, where a branch was created off of the second commit and merged back in after 3 further commits.
Explain what the difference between
git pull and
git fetch is
Draw and explain how
git merge works compared to
1.0 Initialising a new Git repository
Create a new directory
Create a new Git repository
Add a file with the text “Hello” from the command line
Add this file and commit it using Git
1.1 “Pushing” to GitHub
Create a new repository on GitHub
Setup your local repository to have a new remote
Push your code to GitHub
1.2 Working with changes
Open the file in your text editor and make some changes to it
Stash these changes
Unstash them and commit them
Reset to the first commit you made using the
Recover the previous commit using
Create a new branch and switch to it
Add and commit a new file with your name in it
Switch back to the master branch and merge your branch in
Delete your merged branch
Add the following alias:
git config --global alias.l "log --graph --pretty=oneline --abbrev-commit --decorate"
git log and your new alias
Make changes to both files
git diff identify your changes
Add one of the files but do not commit it
git diff to
git diff --staged