Sunday, January 19, 2014

How to set up Git and GitHub on Mac in 10 minutes

Git is one of the fastest and pretty good SCM (software configuration management) tool that has been used extensively by everyone since a couple of years. There are fundamental differences in the way Git as a SCM operates but that's not in the scope of this article. Click Here for an awesome crash course in Git if you are interested to learn more about it. 

This tutorial will tell you how you can use GitHub. The steps are:

1. Install Git on your computer, in this case Mac. 
2. Create an account on GitHub.com. If you are a developer and serious about giving your GitHub link to the recruiters then coin a sober name. Rest of the process is straight forward.
3. Create a repository.
4. Open your terminal. Connect the folder on your Mac where you store/will store your code to a reporsitory in your GitHub account. 
5. Commit/Push the code to your GitHub account! 
Voila! It's done! Okay, not yet. 

Let's take a detailed look at each of the steps.. 


1. Install Git on your computer

Rush to http://git-scm.com/downloads with the speed of light. Download Git for whatever OS you are using. In case of Mac it would be a *.dmg file. Double click - > Install it. Done!

2. Create an account on GitHub.com
Well, this is pretty easy guys. Remember to give a proper name to your account. If your name is common one, most probably the easy to remember combinations of name & surname would be taken, use your imagination to create a good one. - is allowed so you can try firstname-lastname. Once done it will look something like this.. 



3. Create a GitHub repository
Think of a repository as a top level package for your code. You can have multiple repositories with a single GitHub account. You commit your code into one of your repositories in your GitHub account. Click Repositories tab on the profile page of your's and just follow the instructions. Select the public repo option as the private repositories cost money. Once done the screen will look like this.. I have erased my personal details from the screenshots..



Here, helloworld is the name of the repository. It tells you how to set up the repository through the command line and that's what we are going to do now..


 4. Connect the folder on your Mac where you store/will store your code to a repository in your GitHub account.

Just follow the following screenshots that I did. In my case my code is in the folder github/repositories/helloworld

I have scrambled my personal details.. 

Goto the folder where you have your code/files to store on GitHub. And run command git init as shown below


You can see that we have added the files that we need to push to out GitHub repo using command git add *.txt

Once GIT is set up properly, you will get to see .git file created. This is a hidden file so you need to use ls -a . Then you can commit the files you want. I have only once file for demo purpose.  -m is for message and my message is "first commit ever :)" 


 And then once we commit the files, we can push the files to the GitHub. Remember that when you do commit the files are still on your local machine. Hey but wait, what's that error it shows.. it says No configured Push destination. ! Yes, we have not yet connected out GitHub account & repo to this folder. Time to do just that..  use the command given in the repo screen shown in step 3.

Once that happens, you can do the next step that is to finally push the files to remote location.



That's all!  Simple, ain't it? :)

No comments:

Post a Comment