Git linking local repository to remote repository – How to link your local repository to the remote repository to protect your project.

You have a deposit git locally that you'll like linked to the empty repository you created online. We show the steps to do it.

You have been working for a while on your project locally using git.

Now that the project is taking shape, you would like to send it to your online server to work on it with your collaborators or perhaps to protect it in the event of data loss on your machine.

Whatever your goal, we will in this tutorial show how to link your local git repository to the remote repository created online. The goal is to be able to do “push” or “pull” if needed.

Git linking local repository to remote repository – How to link your local repository to the remote repository to protect your project.

This tutorial is not a tutorial that teaches you how to use Git. You'll notice that we haven't bothered to say what git really is.

This is a tutorial made for beginners and experienced people who have forgotten the command sequences used to perform this maneuver.

Before starting, make sure you have:

  • Already a local git repository
  • Creates an empty remote repository.

Now that everything is ready, we can begin.

Commands to link its local git repository to its remote repository

We will first add the url of the remote repository

git remote add origin remote_project_url.git
  • origin : corresponds to the alias of the url of your remote repository. We can give it another name. Usually origin is preferred.
  • remote_project_url.git : This is the url of the remote git repository. It is found when you cilque the button Clone in some git server provider web page like github or bitbucket. Usually used to clone a repository with “git clone url.git”. 

We will then check if our remote repository is registered.

git remote -v

Now that this is confirmed, we will pull the remote repository (which should ideally be empty) to the main branch of our local project. Usually it is called master.

git pull origin master

During the execution of this command you will be asked to enter the password of your remote repository. This pull may generate some conflict. For our it is generally at the level of .gitignore.

Now all we have to do is do the first “git push” which isn't as easy to write the first time around.

git push --set-upstream origin master

In this push we will tell git that our current project must synchronize with the master branch of the remote repository. If all goes well we will just have to enter the password of the remote repository and it's over.

Your local repository is now fully synchronized with your online repository. That's it for the tutorial. In short, here is the summary of the commands.

Order reviews

git remote add origin remote_project_url.git

git remote -v git pull origin master git push --set-upstream origin master

Git: How to link your local git repository to the remote repository
Image by Markus Spiske from Pixabay

ON THE SAME TOPIC