git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Sskillzero@gmail.com <skillzero@gmail.com>
Date
May 25, 2010, 19:40 UTC
Message-ID
<AANLkTinxohzZE6uinzYPIAx3iVjw7afDLsr9MPMUAvHj@mail.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?

Next: Björn Steinbrink
Message 1 of 4 in “git branch --track to link existing local branch to remote?”
  1. skillzero@gmail.comMay 25, 2010
  2. Björn SteinbrinkMay 25, 2010
  3. completion: --set-upstream option for git-branchMichael J Gruber, May 26, 2010
  4. Joshua JensenMay 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.