My favorite git repository is github. It is free unless you want to create a private repository. For private repositories you have to pay a monthly price but it is not mandatory. So if you want a free repository of your source code or documents, go to https://github.com/ and create an account.
Creating a repository in github
Once you have created an account on github, login and you should be able to see you your dashboard somewhat like below:
The red circled button in the above picture is for creating a new repository. To create a new repository click on it.
Once you click on it you will be asked to provide a name of the repository.
Let’s call our repository “ExampleRepo”. Also, provide a short description so that you can distinguish one repository to another at a later time. If you want to make it private repository for some reason, you can select the Private option, we will keep it public in this example. Ideally, every git repository should have a README file in it, and GIT is kind enough to create a blank README file for you. To create a README file at the time of creation of the repository check the “Initialize this repository with a README” option. The below picture shows the important field to notice.
Now click on the Create Repository button and your GIT repository is created.
Cloning a GIT repository
Tortoise GIT
Now for working on files and uploading or downloading files from a Windows machine, you need a Windows client. There are many available on the web the one we will discuss here is called TortoiseGit. You can download it from here.
Git For Windows
TortoiseGit is a shell extension which means it is integrated into Windows Explorer. For working with TortoiseGit you will need a Windows git.exe which TortoiseGit will call everytime it needs to execute any GIT command. The one I chose is called “Git For Windows“. You can download and install it from here.
Once both the above software are installed on your windows machine, you are ready to download the GIT repository you just created. In GIT term this is called Cloning.
- Select a folder in your Windows Explorer where you want to clone the GIT repository and right click on it. In my case, I have a folder called Misc and I want to download/clone my new repository in Misc.
- When I right click on Misc, I can see an option called Git Clone… in the drop-down menu.
- Click on it. You will see it is asking for the URL of the GIT repository from where it has to clone. Go inside the repository ExampleRepo in your github and copy the text in the address bar which should be in this case https://github.com/vivekbhadra/ExampleRepo
- Paste this into the TortoiseGit Git Clone window.
It is showing you in which folder you want to clone the repository. If you like you can browse and choose a different folder at this point too.
Now click on the OK button and you will see the repository has been cloned for you.
Close this window.
Now if you go back to the Misc folder or wherever you have cloned the repository, you will see a new folder has been created inside called ExampleRepo. Go inside this folder you will see there is only a single file called README.
Populating the repository with new files
Adding new files locally
Let’s say you want to version control a file called abc.doc and another file called xyz.c. I have taken two different types of file, one a word document and another a c source file. Usually, you want to keep your repository separate for the separate type of files. In this case, I wanted to choose random file types to show the file type is irrelevant for version control by GIT.
So copy abc.doc and xyz.c in the ExampleRepo folder in Windows. Now that these two files are added my ExampleRepo folder in Windows looks like this:
Making the changes in the local repository folder permanent
Now we need to make these files permanent in our local repository folder in Windows. To do that:
- right click on the ExampleRepo folder in Windows.
- You will see an option Git Commit -> “master”… on the explorer menu. This means to commit your changes in this folder i.e. make these files permanent in the local windows folder.
- Click on the above option. You see a window coming up on your screen and asking for some more information about the commit you are going to make.
- Fill in the Message box with some description of the commit, what it is, why you want to do it etc (anything sensible which gives anyone a brief idea why this file was committed. Then look down there is a list of all the files being committed. Check the files you want to commit i.e. make those permanent in the local repository. In this example, if you notice in the below picture, there is a windows backup file marked with a ~ has not been checked for commit as it is not a file we wish you commit.
Now click on the commit button and you will something like this:
Close the window.
Pushing your changes to GIT repository (the master)
Now to push back these new files into the remote github repository (called the “master”) follow the below steps in Windows:
- Right-click on the ExampleRepo folder, click on TortoiseGit and you will see an option Push.
- Click on the Push option. You will see a Window like the below:
- Just leave it as it is and click on OK button and you will see the below window indicating the push has happened successfully.
Now go back to your github repository and you should be able to see the new files in the list.
If you make any change in the files further, just follow the steps to commit as described above and then push it back as described above and all your new changes should be there in the github repository.
Please note all we discussed here are in public mode and will be visible to anyone on the internet. So do take necessary care not upload any sensitive file of yours in the github.
Leave a Reply