# git branch --track to link existing local branch to remote?

4 messages from 2010-05-25 to 2010-05-26. Participants: skillzero@gmail.com, Björn Steinbrink, Joshua Jensen, Michael J Gruber.
Thread: https://gitlist.dev/t/23904

## skillzero@gmail.com, 2010-05-25 19:40

Subject: git branch --track to link existing local branch to remote?
Message-ID: <AANLkTinxohzZE6uinzYPIAx3iVjw7afDLsr9MPMUAvHj@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinxohzZE6uinzYPIAx3iVjw7afDLsr9MPMUAvHj%40mail.gmail.com

```
Is there a way to link a local branch, which already exists, to a
remote branch without editing the git config file? I create a local
repository and committed some changes, created a remote repository,
added the remote to the local repository, and then pushed the local
branch to the remote. Now the local master points to the same commit
as origin/master. However, the branches aren't linked in the config
file so I can't just do git pull.

I know I can manually edit the config file (as the error message on
git pull says), but it seems like 'git branch --track master
origin/master' should do that automatically, especially if both
branches point to the same commit. It currently complains that the
branch master already exists and -f doesn't let me replace the current
branch. So what I've had to do is create a temp branch, switch to it,
do git branch -f --track master origin/master, and then delete the
temp branch. Is there a better way?

```

## Björn Steinbrink, 2010-05-25 19:53

Subject: Re: git branch --track to link existing local branch to remote?
Message-ID: <20100525195303.GA8174@atjola.homenet>
URL: https://gitlist.dev/e/20100525195303.GA8174%40atjola.homenet
In-Reply-To: <AANLkTinxohzZE6uinzYPIAx3iVjw7afDLsr9MPMUAvHj@mail.gmail.com>

```
On 2010.05.25 12:40:40 -0700, skillzero@gmail.com wrote:
> However, the branches aren't linked in the config file so I can't just
> do git pull.
[...]
> So what I've had to do is create a temp branch, switch to it, do git
> branch -f --track master origin/master, and then delete the temp
> branch. Is there a better way?

With git v1.7.0 or newer:
git branch --set-upstream master origin/master

Björn

```

## Joshua Jensen, 2010-05-25 19:55

Subject: Re: git branch --track to link existing local branch to remote?
Message-ID: <4BFC2B18.2050904@workspacewhiz.com>
URL: https://gitlist.dev/e/4BFC2B18.2050904%40workspacewhiz.com
In-Reply-To: <AANLkTinxohzZE6uinzYPIAx3iVjw7afDLsr9MPMUAvHj@mail.gmail.com>

```
skillzero@gmail.com wrote:
> Is there a way to link a local branch, which already exists, to a
> remote branch without editing the git config file?
git branch --set-upstream

Josh

```

## Michael J Gruber, 2010-05-26 08:46

Subject: [PATCH] completion: --set-upstream option for git-branch
Message-ID: <72c4f4098dea94e21d44b8f76965ff1cb26eab72.1274863387.git.git@drmicha.warpmail.net>
URL: https://gitlist.dev/e/72c4f4098dea94e21d44b8f76965ff1cb26eab72.1274863387.git.git%40drmicha.warpmail.net
In-Reply-To: <20100525195303.GA8174@atjola.homenet>

```
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
On that note, I'm still wondering what's wrong with this one ;)

 contrib/completion/git-completion.bash |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 545bd4b..57245a8 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -797,6 +797,7 @@ _git_branch ()
 		__gitcomp "
 			--color --no-color --verbose --abbrev= --no-abbrev
 			--track --no-track --contains --merged --no-merged
+			--set-upstream
 			"
 		;;
 	*)
-- 
1.7.1.345.g59eb63

```
