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

Re: Using the --track option when creating a branch

From
SBSanti Béjar <santi@agolina.net>
Date
Oct 29, 2008, 16:25 UTC
Message-ID
<adf1fd3d0810290925s493cdc6oc7534904c864db28@mail.gmail.com>
In-Reply-To
<18696.32778.842933.486171@lisa.zopyra.com>
On Wed, Oct 29, 2008 at 4:23 PM, Bill Lear <rael@zopyra.com> wrote:
Show 15 quoted lines
> We have had a few "crossed stream" problems when developers are
> working on a local branch and they do an unguarded git push/pull,
> when they really intended to do git push/pull origin branchname.
>
> We use git in a way that makes it desirable for us to only push/pull
> to the same remote branch.  So, if I'm in branch X, I want 'git push'
> to push to origin/X, and 'git pull' to fetch into origin/X and then
> merge into X from origin/X.
>
> In other words, we want git push/pull to behave in branches other than
> master the same way it does when in master.
>
> I have discovered the '--track' option when creating a local branch,
> and this appears to me to be the thing that gives us the desired
> behavior.

branch.autosetupmerge controls if --track is used by default (it is true by default since a long time) (See "git help config" for details)

>
> Before I tell the rest of the team that this is the correct way
> to do things, I need to be sure I am correct, so if anyone here
> can confirm or deny this, I'd appreciate it.

It should just work (at least in the lastest releases) when creating a branch from a remote branch.

$ git checkout -b X origin/X or $ git branch X origin/X Branch X set up to track remote branch refs/remotes/origin/X

>
> Also, once a branch has been created, how can we add a '--track' option
> after the fact?

It it just two configs (apart from the remote repository). A help message should appear when using "git pull" without arguments and it cannot figure out the branch to merge:

$ # currently in branch next $ git pull You asked me to pull without telling me which branch you want to merge with, and 'branch.next.merge' in your configuration file does not tell me either. Please name which branch you want to merge on the command line and try again (e.g. 'git pull <repository> <refspec>'). See git-pull(1) for details on the refspec.

If you often merge with the same branch, you may want to configure the following variables in your configuration file:

    branch.next.remote = <nickname>
    branch.next.merge = <remote-ref>
    remote.<nickname>.url = <url>
    remote.<nickname>.fetch = <refspec>
See git-config(1) for details.
[end]
so to add it after the fact you should execute:

$ git config branch.next.remote origin $ git config branch.next.merge refs/heads/next

>
> Finally, is there a 'global' config setting that would set this behavior
> for all repos (new or existing)?
See above.
>
> We are using git 1.6.* versions here, mostly.
>
Santi
Previous: Bill LearNext: Bill Lear
Message 2 of 23 in “Using the --track option when creating a branch”
  1. Bill LearOct 29, 2008
  2. Santi BéjarOct 29, 2008
  3. Bill LearOct 29, 2008
  4. Sam VilainOct 30, 2008
  5. Bill LearOct 30, 2008
  6. Bill LearOct 30, 2008
  7. Andreas EricssonOct 30, 2008
  8. Samuel TardieuOct 30, 2008
  9. Andreas EricssonOct 30, 2008
  10. Samuel TardieuOct 30, 2008
  11. Pierre HabouzitOct 30, 2008
  12. Samuel TardieuOct 30, 2008
  13. Sam VilainOct 30, 2008
  14. Andreas EricssonOct 30, 2008
  15. Samuel TardieuOct 30, 2008
  16. Andreas EricssonOct 30, 2008
  17. Bill LearOct 30, 2008
  18. Marc BranchaudOct 30, 2008
  19. Sam VilainOct 30, 2008
  20. Jakub NarebskiOct 30, 2008
  21. Jeff KingNov 2, 2008
  22. Sam VilainOct 30, 2008
  23. Santi BéjarOct 30, 2008

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.