User Tools

Site Tools


git_adding_remotes

Overview

How to add, use and delete remotes, using Linux kernel source repo as an example.

Add a new remote

Currently one remote:

$ git remote -v
origin	https://github.com/torvalds/linux.git (fetch)
origin	https://github.com/torvalds/linux.git (push)
$

Query linux-next before adding it as a remote:

$ git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

Add as a new remote with name ln:

$ git remote add ln https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

There are no new branches yet:

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

But we have a new registered remote:

$ git remote -v
ln	https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git (fetch)
ln	https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git (push)
origin	https://github.com/torvalds/linux (fetch)
origin	https://github.com/torvalds/linux (push)
$

Fetching the new remote

Count the current objects:

$ git count-objects -v
count: 0
size: 0
in-pack: 6542717
packs: 1
size-pack: 2684927
prune-packable: 0
garbage: 0
size-garbage: 0
$

Fetch:

$ git fetch ln
remote: Counting objects: 43368, done.
remote: Compressing objects: 100% (16663/16663), done.
remote: Total 43368 (delta 32248), reused 36955 (delta 26665)
Receiving objects: 100% (43368/43368), 36.62 MiB | 23.38 MiB/s, done.
Resolving deltas: 100% (32248/32248), done.
From https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next
 * [new branch]                akpm          -> ln/akpm
 * [new branch]                akpm-base     -> ln/akpm-base
 * [new branch]                master        -> ln/master
 * [new branch]                pending-fixes -> ln/pending-fixes
 * [new branch]                stable        -> ln/stable
 * [new tag]                   next-20190306 -> next-20190306
$

Count objects again:

$ git count-objects -v
count: 0
size: 0
in-pack: 6586085
packs: 2
size-pack: 2723617
prune-packable: 0
garbage: 0
size-garbage: 0
$

Branches:

$ git branch -a
* master
  remotes/ln/akpm
  remotes/ln/akpm-base
  remotes/ln/master
  remotes/ln/pending-fixes
  remotes/ln/stable
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$

Working with the new remote

Check out a branch

As long as a branch name is unique across all remotes:

$ git checkout akpm
Branch 'akpm' set up to track remote branch 'akpm' from 'ln'.
Switched to a new branch 'akpm'
$
$ git branch -vv
* akpm   02565b639c3b [ln/akpm] drivers/media/platform/sti/delta/delta-ipc.c: fix read buffer overflow
  master 610cd4eadec4 [origin/master] Merge branch 'x86-uv-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
  $

Explicitly track a remote branch

If there is a conflict with branch names:

$ git checkout -b lnmaster --track ln/master
Branch 'lnmaster' set up to track remote branch 'master' from 'ln'.
Switched to a new branch 'lnmaster'
$

Deleting a remote

$ git fsck --no-reflogs
Checking objects: 100% (6708499/6708499), done.
Checking connectivity: 6708499, done.
$
$ git remote remove ln
$ git remote
origin
$
git_adding_remotes.txt · Last modified: 2019/03/08 14:46 by rpjday