How to Connect a Local Git Repository to a Remote One

You may have a local GIT repository that needs to be pushed to a remote GIT repository. In order to connect the two, you would have to use the git-remote command.

If you attempt to use the git-push command in the local repository, without having a remote repository already set up, you will encounter an error similar to the following:

$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

The error message teaches us what to do:

# this will add a new remote called "origin"
# pointing to the remote repository located at REPOSITORY_URL
$ git remote add origin REPOSITORY_URL

# this will push all local branches to the newly created remote
$ git push --all origin

If you need all branches to automatically use this remote repository when you use git-pull, you would need to also add --set-upstream to the push command:

$ git push --all --set-upstream origin

Check the Full Official Documentation for more options on git-remote and git-push.

Feel free to contact us or shoot us an email at if you need more help.