Skip to content

Instantly share code, notes, and snippets.

@kettanaito
Created June 20, 2020 16:02
Show Gist options
  • Save kettanaito/65fa98051c1ebe3f1d019fd5096f03a6 to your computer and use it in GitHub Desktop.
Save kettanaito/65fa98051c1ebe3f1d019fd5096f03a6 to your computer and use it in GitHub Desktop.
Working with remotes in Git

Working with multiple remotes

Adding a new remote

$ git remote add REMOTE_NAME REMOTE_URL

Verify that the new remote has been added by running git remote -v and seeing your REMOTE_NAME in the list.

Synchronizing with a remote

# Pull the latest changes from the BRANCH_NAME of the REMOTE_NAME:
$ git fetch <REMOTE_NAME>/<BRANCH_NAME>

# For example: git fetch chris/master

Once the remote is fetched, you can rebase your branches upon that remote:

$ git checkout <MY_BRANCH>
$ git rebase <REMOTE_NAME>/<BRANCH_NAME>

# For example: git rebase chris/master

This command will add the commits you miss from chris/master into your MY_BRANCH branch.

Pushing to a remote

To push changes into a different remote use this command:

$ git push <REMOTE_NAME> HEAD:<BRANCH_NAME>

# For example: git push chris HEAD:master

This pushes your current branch into chris/master.

Be careful when pushing to remotes you don't own. Always ask the owner for the remote before doing so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment