Gotta use Git

Asif Ahmed

I just got my new Macbook Air a couple days ago so I’ve been messing with that a lot. I’ve been putting off posting about Git and Github until I got my Mac because I feel like Git will work better with a UNIX based operating system like the Mac OS or Linux rather than Windows. I was using Git to host some code for my jQuery posts but I was using a GUI to upload code to Github.

In this post we will be learning about Git and Github via the raw command line interface. Git is a tool for version control. Most companies use SVN for version control, but hipper companies are changing to Git. Version control is mainly used for code projects that involves a team of people that are working on different aspects of the project. If allows for one user to check out a version of the code and another user to check out a different version of the code. This is especially useful in enterprise when a company might have to support 2, 3, or more versions at once for their customers. Git can also be used if you are the only one working on a project. Suppose you have a beautiful working copy of your code and you want to add some functionality to it. You end up adding that functionality but your code keeps crashing now. What happens if you can’t undo it to the original state. With Git you can revert to previous versions, see the difference between the current version and the previous version, and when you check code back into your repository (code storage) you can see what changes you have made. Also if you are working with a team you can see what changes they have made. For more info on why you should use Git please check here. If you want a reason why you should learn Git in a good tutorial, you can check WhoIsHostingThis’s intro to Git.

Today, we will be mostly be using the tutorial from Git Immersion to learn and set up our Git and Github. First after we have installed Git, we have to set up our username and email address with these commands:

git config --global "Your Name"
git config --global ""

The next step is to code something so you could store it in a online repository. Afterwards we will look at some sample git commands.

To initialize a repository you would execute git init .

To add a file to the list of changes to be committed execute git add "filename"

To actually commit the list of changes to the repository execute git commit -m "filename"

Suppose you make some changes to a file and you want to return to the most recent committed version. You would execute git checkout "filename".

Suppose we make some stupid changes to a file and then commit those changes. We then want to revert to the previous (non-stupid) version. We would execute git revert HEAD.

To remove a file execute git rm "filename"

The Git Immersion tutorial definitely covers a lot more detail than we need to get our code hosted on Github. Tomorrow I’ll cover the basics of hosting code on Github.

  • Rita

    That’s relaly shrewd! Good to see the logic set out so well.