Skip to content

Working with Remotes

Zhamri Che Ani edited this page Apr 11, 2020 · 9 revisions

How to:

Show the Stored URLs
$ git remote
$ git remote -v


Adding Remote Repositories

  $ git remote add <remote_short_name> <url>

eg:
+  $ git remote add origin https://github.com/zhamri/MyClass-Git.git
-  $ git remote add myclass https://github.com/zhamri/MyClass-Git.git

Clone an Existing Remote Repository

  $ git clone <url>

eg:
  $ git clone https://github.com/zhamri/MyClass-Git.git

Fetching from Your Remotes

  $ git fetch <remote_short_name>

eg:
+  $ git fetch origin
-  $ git fetch myclass

Pulling from Your Remotes

  $ git pull

Pushing to Your Remotes

  $ git push <remote_short_name> <branch_name>

eg:
+  $ git push origin master
-  $ git push myclass master
-  $ git push myclass master --tags

  $ git push -u <remote_short_name> <branch_name>

eg:
+  $ git push -u origin master

If you use -u in the command, it will remember your preferences for remote and branch and you can simply use the command git push next time.

Inspecting a Remote

  $ git remote show <remote_short_name>

eg:
+  $ git remote show origin
-  $ git remote show myclass

Renaming Remotes

  $ git remote rename <old_remote_short_name> <new_remote_short_name>

eg:
  $ git remote rename stiw3054 stiw3054-RT

Deleting/Removing Remotes

  $ git remote remove <remote_short_name>

+  $ git remote remove stiw3054-RT
-  $ git remote rm stiw3054-RT

Setting Upstream

  $ git push --set-upstream <remote_name> <branch_name>

eg:
  $ git push --set-upstream origin master

References:

https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
https://help.github.com/articles/removing-a-remote/