Version Control with Git
- Creating a Repository
Learning Objectives
- Explain how to create a Git repository locally.
First, we need to download the demonstration code to our computer. It's stored in git, so we do it as .
$ git clone http://github.com/Southampton-RSG/2019-11-19-southampton-swc
This will download all our test files to our computer. Don't worry, we'll explain this bit later!
Now, let’s change to our code directory.
$ cd ~/2019-11-19-southampton-swc/novice/git/code
$ ls
climate_analysis.py temp_conversion.py
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.py .git temp_conversion.py
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.py
temp_conversion.py
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.