Installing Git and Setting Up Accounts

Git is a Version Control System (VCS) that has gained a lot of traction among the programming community. We will want to use version control to keep track of the files we write, and the changes we make to them.

Account Creation

During the course we will show you how to use GitHub to host some of your work and do code related project management. You will need to set up an account:

  • Please register for a GitHub account
  • When choosing a username we recommend not using a name that includes an employer or university in case you move later on
  • i.e. 'johnsmith' or 'johnsmith86' are OK, 'johnsmithUZH' probably not

Mac Users

Installing Git

We will install Git using Homebrew. Enter the following lines of code into your terminal:

1
2
brew install git
brew link --force git

Then close and reopen the terminal. Now Verify your installation

Autocompletion

When we code we want to be lazy - we don't always want to write out the whole line of code we want to enter, and would prefer the computer to autocomplete our line of code for us. The OSX terminal doesn't have this autocompletion by default, so let's add it using our trusty friend Homebrew.

Open a terminal and enter:

1
brew install bash-completion

This installs 'bash completion' into a file /usr/local/etc/bash_completion.d.

To make the autocompletion work, type the following into your terminal:

1
echo "[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion" >> ~/.bash_profile

And restart your terminal session:

1
source ~/.bash_profile

Checking Autocomplete works

Now you can autocomplete by pressing tab twice after a command. We will demonstrate this in class.

For now, enter the following into you terminal and press tab twice (which we depict as [tab] [tab]) below:

1
git [tab] [tab]

which will then show:

1
2
3
4
5
6
$ git [tab] [tab]
add            blame          cherry-pick    config         format-patch   gui            merge          push           repack         rm             stage          whatchanged
am             branch         citool         describe       fsck           help           mergetool      range-diff     replace        send-email     stash          worktree
apply          bundle         clean          diff           gc             init           mv             rebase         request-pull   shortlog       status
archive        checkout       clone          difftool       gitk           instaweb       notes          reflog         reset          show           submodule
bisect         cherry         commit         fetch          grep           log            pull           remote         revert         show-branch    tag

Linux Users

Git should be installed already for you. To check if it is, enter the following in a terminal:

1
git --version

If you get a bunch of numbers (ideally starting with 2.15) or higher - you are good to move on.

If not, install it by entering the following into the command line:

1
sudo apt-get install git

Once complete, verify your install.

Windows Users

Git will be already installed inside your Ubuntu terminal. Verify this, by following these instructions.

Verifying your install

To verify your installation, type the following command in a terminal and press the return key:

1
git --version

You should get an output that looks like:

1
git version 2.18.0

Ensure that you have a version greater than 2.15.0 installed.