Version Control with Git

Creating a Repository

Learning Objectives

  • Create a local Git repository.

Download workshop data

Once Git is configured, we can start using it. Let’s first download some of the data we are using for this workshop. Move the data-files folder to the desktop.

Now that we have our data folder, lets create a folder for all of our workshop R scripts and move it into that folder.
$ cd ~/Desktop
$ mkdir software-carpentry-2016
$ mv data-files software-carpentry-2016/
$ cd software-carpentry-2016

Then we tell Git to make software-carpentry-2016 a repository—a place where Git can store versions of our files:

$ git init

If we use ls to show the directory’s contents, it appears that nothing has changed:

$ ls

But if we add the -a flag to show everything, we can see that Git has created a hidden directory within software-carpentry-2016 called .git:

$ ls -a
.   ..  .git

Git stores information about the project in this special sub-directory. If we ever delete it, we will lose the project’s history.

We can check that everything is set up correctly by asking Git to tell us the status of our project:

$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)