Git is a version control system. More specifically it’s a distributed version control system.
For those of you who don’t know hat versioning is. Here’s a small anecdote to get you up to speed.
I was working in a project where I was the developer and I had a fellow team mate testing my code. I used to complete my code and inform him of the updates and ask him to proceed with the testing. This was what he used to do. Download the latest version of the code into a folder with the current date as its name. Test the code and then let me know of any bugs.
This was his folder structure
He was manually keeping a log of updated code at every stage. Don’t you think this was kind of redundant ant time consuming? This is where version control kicks in. Imagine a scenario where in, I can code, update my changes and add it as a commit to my remote repository. Inform the tester about the updates, he/she does a checkout of the latest version of the code. Adds review comments to the commit. I read those comments, make the changes and then commit my changes. Makes more sense doesn’t it? Well Git is one such tool, which I’ve grown to love. I must thank my friend Senthil for introducing me to Git.
If your on Windows, you need to download and install git. (Link) Mac comes with git preinstalled :-) Edit : I’m so used to having Xcode installed on any Mac that I thought Git actually came pre installed with Mac. Correction, it doesn’t, and must be installed from here (Command Line Tools) or via HomeBrew as suggested by my friend Akash. Linux, download and install (Link)
If your adding git support to an existing project
- Navigate to your source directory.
- It initializes an empty repository
- Next, type
- This adds all the current files to git
- Next, type
If your starting a new project
- Create a new directory
- And follow steps from 2 to 9 from above
- The only differences will be, as and when you add new files, they aren’t tracked by git by default.
- You need to add them by typing in
Next, I’ll talk about adding remote support. Remote support works best in a Unix environment
- Create a new folder in your remote machine as
.git. The.git is not mandatory.
- Then key in
- This initializes a bare repository
- Head over to your machine and navigate to the project folder
- Key in
- This adds a remote using ssh to your git repository
- Once done. Key in
- You’ll be asked for credentials, supply the same. You can skip this by using ssh keys.
- As and when you make changes to one of your Local copies, commit and then push to the remote.