Git Remote Tips

When you’re dealing with Git, eventually you’ll want to push your code to a remote repository. There are a few useful commands to be aware of. First, you can see which remote repositories are associated with your repo:

> git remote -v
origin	git@github.com:dev-diaries/web.git (fetch)
origin	git@github.com:dev-diaries/web.git (push)

You can have several remote repositories linked from the same repository and name it whatever you like:

> git remote add client-repo git@github.com:client-org/project.git
> git remote -v
origin          git@github.com:my-org/project.git
client-repo     git@github.com:client-org/project.git

Then, to push to that particular repo you’ll need to specify it instead of origin:

git push client-repo master

When typically we would write:

git push origin master

To remove a repository you can run:

> git remote -v
origin          git@github.com:my-org/project.git
client-repo     git@github.com:client-org/project.git
> git remote remove client-repo
> git remote -v
origin          git@github.com:my-org/project.git

We talked about renaming a local branch and you can also rename a remote repository name

> git remote -v
origin          git@github.com:my-org/project.git
client-repo     git@github.com:client-org/project.git
> git remote rename client-repo the-client-repo
> git remote -v
origin              git@github.com:my-org/project.git
the-client-repo     git@github.com:client-org/project.git

It is useful to be able to return more information about a remote repository:

> git remote show origin
* remote origin
  Fetch URL: git@github.com:dev-diaries/web.git
  Push  URL: git@github.com:dev-diaries/web.git
  HEAD branch: master
  Remote branches:
    api                                    tracked
    dev                                    tracked
    master                                 tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local refs configured for 'git push':
    api    pushes to api    (up to date)
    master pushes to master (up to date)

Read more about it here

Instagram Post