Git remotes - Connecting your local site to a remote repository

Working with Git is great, but before you see the real benefits of using Git you'll need to have your project hooked up to a remote repository.

Most people enter the world of Git when they are brought on to a project with multiple developers. In this case, there is likely already an existing repo, and all you need to learn to do is pull the latest changes, and push your own.

Navigating to your code in the terminal

First, you'll need to get a local site up and running. You can do so using MAMP, Kalabox, or any other tool that makes that easier, but make sure you can find out where the files are saved on disk. You'll need to get there from the command line to follow along with the rest of this post.

Open your terminal, and navigate to this location. I do this using the cd command. cd stands for "change directory".

$ cd ~/Sites/

To check your location you can also run the command pwd which stands for "present working directory".

Check to see if there is already a Git repo

Once you have made it to the desired directory, run the command git status to see if the directory is already a git repository. If you see the error...

fatal: Not a git repository (or any of the parent directories): .git'll know it's not. However, if you see a result that starts with On branch master or similar, you will know that you already have a Git repository set up.

Cloning a new local project from a remote Git repo

If you don't already have the code you want to edit on your computer, you can clone from the repo information provided by your teammates. First navigate to the parent directory where you would like the code to be, then use the git clone command.

git clone

This will bring the entire code base - already hooked up to it's remote - onto your computer.

Connecting an existing local project to a remote repo

If you are on a Git branch, run the command git remote -v. This will tell you if your local repository is connected to a remote (or more than one remote, in some cases) and what they are. If you see a remote here, then you are done with this step.

However, if the command prompt is returned with no additional remote information, you will need to connect your code to a remote repository. Ask a team member for the repository information, and they will likely give you something that looks like this:

First, initialize Git by running the command git init. Then add the git repo as a remote as follows:

git remote add origin

Add new comment

© 2023 Jeneration Web Development