Creating and associating a local git repository with a repository on Github, using the OS X terminal

June 19, 2014 — Leave a comment

This is just a simple recipe for associating a local git repository with a remote GitHub repository, for those times when creating the GitHub repository first and then checking it out is not an option. I’m currently using version 1.8.5.2 of git.

Step 1: Initialise Git (i.e., create an empty Git repository) inside the local project folder

If the folder already exists, simply enter into the folder using the following command

Then initialise Git within the folder with

If the folder does not already exist on the local file system, the folder can be simultaneously created and initialised with the following command

Then enter the folder with

Step 2: Link the local repository to the remote GitHub repository

From inside the local folder, link it to the remote GitHub repository with the following command (replacing the url with the actual GitHub url)

Note that you can also verify that the remote association has been created with the command

Step 3: Bring the files down from the remote repository to the local repository

To do this, perform a git pull as follows

Step 4: Checkout the files you want to work with from the local repository

All that was done in step 3 was to update the local repository with the files in the remote repository. At this point however, the remote files will not yet show up in the local folder, seeing that they are just still in the local repository. For one to be able to access them in the folder, one must first check them out of the local repository. To do so, do the following

Note also that in order to checkout a particular branch apart from the master, simply replace the word ‘master’ with the name of the branch as follows:

 

TwitterFacebookGoogle+LinkedInDiggRedditStumbleUponEmail

Ifeanyi Isitor

Posts Twitter Google+

I'm a web application developer / independent contractor, currently residing in London.