Git Remotes

Last modified: 
Thursday, April 9th, 2015
Topics: 
Git

Add a remote

Setting the origin path manually:

git remote add origin git@github.com:Your-Github/examples.git

Adding an upstream:

git remote add upstream git@github.com:Upstream-Github/examples.git

Check the remotes are there:

git remote -v
origin  git@github.com:Your-Github/examples.git (fetch)
origin  git@github.com:Your-Github/examples.git (push)
upstream    git@github.com:Upstream-Github/examples.git (fetch)
upstream    git@github.com:Upstream-Github/examples.git (push)

Delete a remote

git remote rm upstream

List tags available on a remote repo

Listing the tags available in an upstream repo:

git ls-remote --tags upstream

Maybe there are a lot of tags, so we pipe to less:

git ls-remote --tags upstream | less

Narrowing down the results with grep:

git ls-remote --tags upstream | grep "mytag" | less

Checking out a remote branch or tag

git fetch upstream
# Here we wait while git pulls down references 
#for all the upstream tags, branches, and so forth.
# ....
#
git checkout -b new_branch remote_tag_or_branch

If you don't want to rename the tag branch locally, you can omit the new_branch name like this

git checkout -b remote_tag_or_branch

Now that you've pulled in all this remote tag info, whenever you run git tag, you'll see all of those tag refs. This can be kind of annoying. Consider that it's common to deploy to web hosts like Acquia using tags, so you can end up with a situation like me where one project may have over 700 tags.

Pulling a remote tag

git pull acquia dev_2014-10-16_12-39-00


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.