• Home
  • LinuxGit
  • How to make an existing git branch track a remote branch?

How to make an existing git branch track a remote branch?

git branch --set-upstream localbranchname remotebranchroot/remotebranchname[/code]

Eg.[/code]

My list of local/remotes:[/code]

[[email protected] supernova-kernel]$ git branch -a
* jan31
master
remotes/origin/HEAD -> origin/master
remotes/origin/UnderVoltVDD_OC
remotes/origin/battery
remotes/origin/jan31
remotes/origin/master
remotes/origin/sense35
remotes/origin/testuv
remotes/origin/vddhavsocuvsysfs[/code]

So, I have to write:

[[email protected] supernova-kernel]$ git branch --set-upstream jan31 origin/jan31
Branch jan31 set up to track remote branch jan31 from origin.[/code]

Following this, we can pull from the remote to get the remote changes to local:

[[email protected] supernova-kernel]$ git pull
Enter passphrase for key '/home/droidzone/.ssh/id_rsa':
Updating fb1198d..e3cc327
Fast-forward
.config | 10 +-
.config.old | 14 +-
.version | 2 +-
System.map |62738 ++++++++++++++++----------------
arch/arm/boot/compressed/piggy.lzma | Bin 1773249 -> 1774507 bytes
arch/arm/kernel/asm-offsets.s | 35 +-
arch/arm/lib/lib.a | Bin 90930 -> 90966 bytes
arch/arm/mach-msm/acpuclock-scorpion.c | 44 +-
arch/arm/mach-msm/avs.c | 30 +-
arch/arm/mach-msm/qdsp6/amrnb_in.c | 302 -
drivers/cpufreq/modules.builtin | 1 +
drivers/modules.builtin | 1 +
drivers/power/ds2784_battery.c | 412 +-
include/config/auto.conf | 7 +-
include/config/kernel.release | 2 +-
include/config/tristate.conf | 1 +
include/generated/autoconf.h | 7 +-
include/generated/compile.h | 8 +-
include/generated/utsrelease.h | 2 +-
kernel/bounds.s | 17 +-
lib/lib.a | Bin 975468 -> 975564 bytes
modules.builtin | 1 +
modules.order | 5 +
usr/.initramfs_data.cpio.d | 2 +-
24 files changed, 31918 insertions(+), 31723 deletions(-)
delete mode 100644 arch/arm/mach-msm/qdsp6/amrnb_in.c
[/code]

Note that sometimes we have to clean the local git and reset it to the last sync state before we can pull.

[[email protected] supernova-kernel]$ git clean
fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean
[[email protected]upernova supernova-kernel]$ git clean -f
Removing .missing-syscalls.d
Not removing drivers/drivers/staging/rt2860/iface/
Removing fs/btrfs/modules.order
Removing fs/ext3/modules.order
Removing fs/fuse/modules.builtin
Removing fs/fuse/modules.order
Removing fs/jbd/modules.order
[[email protected] supernova-kernel]$ git reset[/code]