Git Remote Repositories


This page contains a quick reference to add, delete and maintain remote repositories in Git. This is part 5 of the Git quick reference series.


Remote Repositories

The local or current repository is the repository you are currently working in. The remote repository is any other repositories you exchange files with. The name “remote” is a bit misleading, as a remote repository can be located in the local file system. An upstream repository is the remote repository that your local repository cloned from.

Add a Remote Repository

Remove a Remote Repository

Rename a Remote Repository

Show Remote Repositories

The following command lists all remote repositories

And the following command shows a bit more information about each remote repository, such as what actions are allowed.

Show Branches in Local Repository

The git show-ref command shows all local branches, tags and head:

Show Branches in Remote Repository

The git ls-remote command shows all branches, tags and heads in a remote repository.

If you are in a local tracking branch, you can just do the following:

Push Changes from a Local Tracking Branch to the Remote

Push a Specific Branch to a Remote

Push Changes of a Branch with different name in Local and Remote

Create Local Branch and Push to Remote Repository

The following creates a new branch called branch_name , and pushes it to the remote directory. The -u  option is needed to link the local branch to the remote branch.


Delete a remote branch

Alternatively, you can also use the :branch_name convention. It is like pushing an empty local branch into a remote branch, hence removing it.

Delete a remote tag

Setup a Local Tracking Branch

Make Existing Git branch track a Remote branch

This comment makes the current branch track a remote branch:

Alternatively, we can change another local branch (i.e. not current) with this command:

Remove Branch Tracking

The following command removes the remote tracking  from  the current branch:

Alternatively, we could specify the local branch if different to the current branch:

Repoint Branch to Old Change

A way to rollback changes on a branch is to repoint the branch to an old state.

The combination  git reset --hard and  git push --force is dangerous. This is why it is important to provide the branch name to  git push --force to ensure only the amended branch changes are pushed.


  • Git Reference:
  • Pro Git. Scott Chanon and Ben Straub. APress.
  • Pragmatic Guide to Git. Travis Swicegood. Pragmatic Bookshelf, 2010.
  • Version Control with Git. Jon Loeliger and Mattew McCullough. O’Reilly, 2012

Git Tools

The following two tabs change content below.

Eduard Manas

Eduard is a senior IT consultant with over 15 years in the financial sector. He is an experienced developer in Java, C#, Python, Wordpress, Tibco EMS/RV, Oracle, Sybase and MySQL.Outside of work, he likes spending time with family, friends, and watching football.

Latest posts by Eduard Manas (see all)

Leave a Reply