Version Control with Git
- Creating a Repository
Learning Objectives
- Explain how to create a Git repository locally.
First, if we haven't already 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/softwaresaved/swc-ramp-git
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 ~/swc-ramp-git/code
$ ls
climate_analysis.py temp_conversion.py
Let's assume we've just written these files, and we want to manage their development under version control, using Git.
First, we need to tell Git to create a repository. A repository is 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. So let's not do that.
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.