Git Remotes: Fun Commands You Can Use

Commands discussed in this section:

  • git branch
  • git remote
  • git ls-remote
  • git fetch
  • git pull

List remote-tracking branches

$ git branch -r
  origin/HEAD -> origin/master

List all branches:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master

List only local, working branches:

$ git branch
* master

Show basic information about the default remote

$ git remote -v
origin  file:///home/gitadmin/project1.git (fetch)
origin  file:///home/gitadmin/project1.git (push)

Show a lot about a remote

$ git remote show origin
* remote origin
  Fetch URL: file:///home/gitadmin/project1.git
  Push  URL: file:///home/gitadmin/project1.git
  HEAD branch: master
  Remote branches:
    master tracked
    test   tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Dig around remote repositories

Show the references in a remote repository and their hash:

$ git ls-remote origin
8dc59a3c60b5dd12605d0a647b4921b5410b820f    HEAD
8dc59a3c60b5dd12605d0a647b4921b5410b820f    refs/heads/master
a402bc61da05d2c9dc6dc6307dcffe12a1fb8045    refs/heads/test

$ git ls-remote git://
ee17d863ceab06e408e8b051244b7202ae4075f7        HEAD
ee17d863ceab06e408e8b051244b7202ae4075f7        refs/heads/master
f0847d378161de510b49654746f551482240901f        refs/heads/upstream
7f5b189dc1c67bb5ff33ca2d4f616336baa8fb4c        refs/tags/0.5.19-1

The first example, refers to a remote repository named origin and the second above specifies the completely URL of the remote repository.

Add a remote repository

$ git remote add qa git://qaserver/round1
$ git fetch qa
From git://qaserver/round1
 * [new branch]      master     -> qa/master
 * [new branch]      test       -> qa/test

Add a tracking branch

$ git branch --track test origin/test
Branch test set up to track remote branch test from origin.
$ git checkout test
$ git pull


Recent Articles

Where Do I Get Git?

Where do you get git? We have the answer to that for Linux (Ubuntu, Debian, and Red Hat), Windows, and Apple OS as well as over 30 free git tutorials.

What is the deal with the Git Index? What is the Git Index?

The git "index" is where you place files you want committed to the git repository. Learn more about the git index and git commit by selecting this link.

What Every VCS Must do

Version Control System ("VCS") need to be able to provide to its users? GitGuys explains exactly what it needs to include and provides tutorials on Git.

Visualising Branches And Their Commits

We explain and discuss the use of the git show-branch, gitg, gitk and qgit in this Tutorial. Complete with examples.

“Tracking Branches” And “Remote-Tracking Branches”

Both Tracking Branches and Remote Tracking Branches are created on the git client when a git clone command is used.

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox