Connect local project to remote Git repository

In this post, I will show you how to connect local Git to a remote repository. And this remote repository could be GitHub, Bitbucket, GitLab, or anything else. The process is the same.

Connect your project to a remote Git repository

Before you do anything, make sure Git is installed on your machine. Otherwise, see this post to install Git on your machine (both Windows & Mac) and for the first time Git configuration.

To connect your local Git repo with a remote server, follow the steps below:

Create a remote repository with the same name as the local project

Naming your remote Git repository

Before you connect any project to a remote server, your first instinct should be to create a repository. There are many free Git hosting servers out there. GitHub & Bitbucket are the two most popular of them.

If you want to use GitHub as your remote server, see this post to learn how to create a repository on GitHub.

Make sure you named the repository the same as your local project. For example, you have a project folder called “super-cool-website” on your computer. So your repository name should be the same as the project folder. And this repository could be on GitHub or somewhere else.

Also, make sure that there is no space in the local project or remote repository names.

Add the remote origin to your project

After you create a Git repository on GitHub, Bitbucket, or anywhere, you’ll get a remote origin URL. This URL ends with “.git” as you see below.

Remote Git repository URL on GitHub

Now open your command line or terminal or Git Bash, and make sure that it’s currently pointing to the appropriate folder. And type the following command:

git remote add origin your_repository_url

Don’t forget to replace the “your_repository_url” with the actual URL.

The above command will add your local project to the remote server. If you’re using other than GitHub as your remote server, the process is the same as this one.

To check if the URL was correctly added or not, you can type the following command:

git remote -v (this is not mandatory to check but something good to know).

command to display Git remote URL

To change this remote origin URL in the future or on a different project that you cloned, see this post to learn how to change it.

Push to the remote server/repository

This is the moment you have been waiting for!

After you added the Git remote origin URL, you can push your local project to the remote server where you created the repository. The command is as follows:

git push origin master

Not to mention, you need to initiate Git (git init), add files to the staging (git add -A), and make a commit (git commit -m "custom message") before you push it to the live or remote server.

Here is the list of all the commands:

git init
git remote add origin your_repo_url_goes_here
git add -A
git commit -m "Initial commit"
git push origin master

For the first push, it may ask the username & password of your remote server (GitHub, Bitbucket, etc). However, the prompt is one time and it will not ask you for the username & password each time.

This is how you can connect a local project to a remote server using Git. See the most commonly used git commands and their explanation.

For your additional information

Git may seem confusing for the first time or the moment you have just getting started. But this is not the actual case.

Even, this tiny post may seem confusing to some of you. So I listed some relevant topics below. These will help you to better understand the Git workflow and make your learning path much easier.

How to install Git on Windows & Mac?
What is Git and why it is used?
How to use Git and GitHub?
Why is Git useful for an individual developer?
Basic & starter posts on Git that will give you a rock-solid understanding

How to connect Git Bash to GitHub?

Connecting Git Bash to GitHub is the same process as I showed you above (with the VSCode terminal). However, if this is still not clear to you, here is the simple step-by-step process below.

Step 1: Download and install Git from to your Windows computer.

Step 2: Open Git Bash (command line) from the Windows “Start” menu.

Git installed on Windows computer, Git Bash

Step 3: Navigate to the project folder in the command line. You can type “cd ” and drag & drop the folder to the command line (git bash) and hit enter.

Navigate to a project folder in git bash command line

Step 4: Initiate git using the following command: git init

Initialize git using bash command line

Step 5: Add the remote origin URL using the following command:

git remote add origin

Don’t forget to replace the above URL with yours.

Step 6: Stage all files using git add -A

Stage all files using git bash command line

Step 7: Make a commit for all the changes by git commit -m "Initial commit"

make commit using git bash command

Step 8: Push the project to the GitHub repository using git push origin master

Push local project to GitHub repository using Git Bash

That’s it! Now if you go to your GitHub repository and refresh the page, you’ll see that the local project has been pushed to the live server.

Bonus tip: To close Git Bash, type exit and hit enter.

Video instruction

Learn more about Git


Now you know how to connect your local project with a live & remote repository or server using Git. Additionally, I gave you other related information and basic startup guideline for Git. Therefore, if you still have any questions, you can always come back and ask questions.

Git saves your project locally. In other words, it saves the project on your computer’s hard drive. On the other hand, GitHub, Bitbucket, GitLab, etc save your project on a live server and helps you in many directions such as history, collaboration, fixing merge conflict, etc.

There are many benefits of using Git even if you work alone as an individual freelancer.

Also, a Git remote server protects your projects from any vulnerabilities. Even if you lost your device/computer, the remote servers can help you to restore all the projects in a couple of minutes.