Version Control with Git
- Creating a Repository
Learning Objectives
- Explain how to create a Git repository locally.
So, first let’s change to our code directory. Note that this is not the directory that you were using in the R lesson, but should contain clean versions of the climate analysis and temperature conversion files you will work on now. This is to ensure that everyone has the same files to start the lesson.
$ cd ~/2016-11-01-Southampton/novice/git/code
$ ls
climate_analysis.R temp_conversion.R
Once Git is configured, we can start using it.
Now, lets tell Git to create a repository— A storage area where git records the full history of commits of a project and information about who changed what and when.
$ 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 called .git
:
$ ls -a
. .. climate_analysis.R .git temp_conversion.R
Git stores information about the project in here. If we ever delete it, we will lose the project’s history.
Check Status
We can check that everything is set up correctly by asking Git to tell us the status of our project with the status command:
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
climate_analysis.R
temp_conversion.R
nothing added to commit but untracked files present (use "git add" to track)
A branch is an independent line of development. We have only one, and the default name is master.
The untracked files message means that there are files in the directory that Git isn’t keeping track of.