Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== Overview ===== How to add, use and delete remotes, using Linux kernel source repo as an example. ===== Add a new remote ===== Currently one remote: <code> $ git remote -v origin https://github.com/torvalds/linux.git (fetch) origin https://github.com/torvalds/linux.git (push) $ </code> Query ''linux-next'' //before// adding it as a remote: <code> $ git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git </code> Add as a new remote with name ''ln'': <code> $ git remote add ln https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git </code> There are no new branches yet: <code> $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ </code> But we have a new registered remote: <code> $ 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) $ </code> ===== Fetching the new remote ===== Count the current objects: <code> $ git count-objects -v count: 0 size: 0 in-pack: 6542717 packs: 1 size-pack: 2684927 prune-packable: 0 garbage: 0 size-garbage: 0 $ </code> Fetch: <code> $ 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 $ </code> Count objects again: <code> $ git count-objects -v count: 0 size: 0 in-pack: 6586085 packs: 2 size-pack: 2723617 prune-packable: 0 garbage: 0 size-garbage: 0 $ </code> Branches: <code> $ 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 $ </code> ===== Working with the new remote ===== ==== Check out a branch ==== As long as a branch name is unique across all remotes: <code> $ git checkout akpm Branch 'akpm' set up to track remote branch 'akpm' from 'ln'. Switched to a new branch 'akpm' $ </code> <code> $ 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 $ </code> ==== Explicitly track a remote branch ==== If there is a conflict with branch names: <code> $ git checkout -b lnmaster --track ln/master Branch 'lnmaster' set up to track remote branch 'master' from 'ln'. Switched to a new branch 'lnmaster' $ </code> ===== Deleting a remote ===== <code> $ git fsck --no-reflogs Checking objects: 100% (6708499/6708499), done. Checking connectivity: 6708499, done. $ </code> <code> $ git remote remove ln $ git remote origin $ </code> git_adding_remotes.txt Last modified: 2019/03/08 14:46by rpjday