How to create a local repository with git to provide version control
Let’s say that you just want use git to do version control of some files on your hard disk. You don’t need to create a repository on a server or in the cloud. Just install git on your machine and keep the repository on the same machine or laptop. In our case, we installed git when we install the Heroku Toolbelt. But you could install git on Window with msysgit as well. In both installations, you will get Git Bash which provides a command line window for using git. And Git GUI which is a graphical interface. In this tutorial, we will focus on using Git Bash.
Suppose we have a file in c:/tutorials/learngit/index.html that we want to version control.
1. Open Git Bash (in our case, it was installed in c:\Program Files (x86)\Git\bin.
2. Navigate to our working directory (in our case it is c:\tutorials\learngit), with the command…
cd /c/tutorials/learngit
3. To create a new git repository, type …
git init
You will get a response like …
Initialized empty Git repository in c:/tutorials/learngit/.git/
And it had just created a “.git” folder within your working directory. Because the folder name starts with a dot, this is a hidden folder and you will not be able to see it unless you turn on the option in Windows Explorer as explained here.
4. Type “git status” and it will say that you have “index.html” as “untracked files”. That is because we have not added any files to our newly created git repository. We first add the file to the staging area with …
git add .
5. Now it shows “index.html as a “new file” under “Changes to be committed”. We now commit the file to the repository with …
git commit -m “first commit”
The -m stands for “message” and “first commit” is our message to be associated with this commit. Your first version of the file is in the repository now.
6. Type “git status” and it now shows that you have “nothing to commit, working directory clean”.
7. Now make a change to the file index.html.
8. And commit this file to the repository again. When you get used to this, you can skip the staging and commit directly as described here. We take this short-cut route and add to stage and commit with one command …
git commit -a -m “second commit”
The -a flag tell git to perform the add in the same step.
9. Type “gitk” and you will see a GUI app showing git logs and your two versions and their comments.
Note: This tutorial was shown using git version 1.8.1.msysgit.1. You can see what version of git you have by …
git –version