Connect Local & Remote Repositories with Git Remote

Effortlessly Connect Local & Remote Repositories

Huseyin Gulcu
4 min readApr 28, 2023
git pull & git push

Git Remote is a built-in Git command which is utilized for managing projects using the popular version control system. Its primary purpose is to connect local and remote repositories to facilitate collaborative work across different devices and users. By connecting the remote and local repositories, it enables efficient coordination of changes. This tutorial provides a step-by-step guide on how to use Git Remote for connecting your local and remote repositories. Additionally, we’ll be sharing some useful tips and options that will enable you to maximize the benefits of this command.

How to set up a remote repository as a remote for your local repository?

1) Create a remote repository

create a repository on the Github

Create a new repository on Github, name it, add additional configurations, and then click the ‘Create repository’ button.

2) Copy the address of the remote repository

copy the address of your newly created repository

When you click the Create repository button, the above screen will appear. If you are using SSH, click the SSH button; otherwise, click the HTTPS button to copy the address of the newly created repository to the clipboard.

3) Create a project folder on your PC

create a folder on your PC

You can create a folder for your local repository on your terminal by using mkdir <folder-name> command.

4) Init the local repository

init the local repository

Navigate to your project directory using the cd <folder-name> command, and then run the git init command to initialize your local repository.

5) Set up the remote repository as a remote for your local repository

set the remote repository

run git remote add <remote-name> <address-of-the-remote> command to add a remote repository for your local repository.

6) List the names of your remotes

show your remote

You can list the names of your remotes by running the git remote show command.

7) Push & Pull

Now, you can safely push your local changes to your remote repository and pull the changes made in the remote repository to your local repository.

To rename a remote

rename a remote
  1. First, the command git remote -v is used to list the current remote names and their associated URLs. In this example, the current remote name is "origin" and its URL is git@github.com:hsglc/git-remote.git .
  2. The command git remote rename origin new-origin is used to rename the "origin" remote to "new-origin". The output confirms that the rename was successful.
  3. The command git remote -v is used again to verify that the remote name has been changed. In this case, the output shows that the remote name has been updated to "new-origin" and its URL remains the same.

Overall, these steps demonstrate how to rename a remote using the Git command line interface.

How to customize git push command to use without specifying remote name and branch name

By following the steps below, you can make this configuration:

  1. Run the command git config --global push.default current to set the default push behavior to current instead of simple. This means that you will only push to a remote branch with the same name as your current branch.
  2. Run the command git branch --set-upstream-to=origin/branch-name to specify which remote branch matches your current branch. This command assigns the name of the remote branch that will be tracked by your branch.

After completing these steps, the git push command will automatically push to the remote branch that matches your current branch. However, if the remote branch matching your branch has not yet been created, you will still need to manually write git push origin branch-name.

Conclusion

Git Remote makes project management more efficient by facilitating collaboration among different users and devices working on the same project. In this article, you learned how to connect local and remote repositories using the Git Remote command. You can now collaborate on projects where different users work together using Git Remote. Happy Coding!

--

--

Huseyin Gulcu

I work at a company as a frontend developer to make accessible and elegant web applications.