Getting existing git branches to track remote branches

前端 未结 7 947
一整个雨季
一整个雨季 2021-01-29 21:43

My usual workflow when working with git, is something like this:

  1. create a local repository
  2. do some work in that repository, add/change files etc.
相关标签:
7条回答
  • 2021-01-29 21:50

    Use this command:

    git clone [<options>] [--] <repo> [<dir>]
    
    0 讨论(0)
  • 2021-01-29 21:51

    Use the set-upstream arg:

    git branch --set-upstream local-branch-name origin/remote-branch-name
    

    Running the above command updates your .git/config file correctly and even verifies with this output:

    "Branch local-branch-name set up to track remote branch remote-branch-name from origin."

    EDIT: As martijn said: "In version Git v1.8.0, --set-upstream is deprecated. Use --set-upstream-to instead."

    git branch --set-upstream-to local-branch-name origin/remote-branch-name
    

    See this for more information.

    0 讨论(0)
  • 2021-01-29 21:51

    git help remote should show you what you need to know. I think what you want is

    git remote add [remote-name] [remote-url]
    
    # Set a local branch to follow the remote
    git config branch.[branch-name].remote [remote-name]
    
    # Set it to automatically merge with a specific remote branch when you pull
    git config branch.[branch-name].merge [remote-master]
    

    You can also manually edit .git/config to set these up.

    0 讨论(0)
  • 2021-01-29 21:52

    On newer versions of git you can use

    git branch --track origin/branch_name
    
    0 讨论(0)
  • 2021-01-29 21:53

    The --set-upstream flag is deprecated and will be removed.

    git branch master --set-upstream-to myupstream/master

    0 讨论(0)
  • 2021-01-29 21:56

    Fast forward three years (see what I did there :-) ), I tried to pull an untracked branch using Git Bash and received

    If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> develop
    

    The following achieved what I needed:

    $ git branch --set-upstream-to=origin/develop develop Branch 'develop' set up to track remote branch 'develop' from 'origin'.

    0 讨论(0)
提交回复
热议问题