Clone from a branch other than master

前端 未结 4 666
不思量自难忘°
不思量自难忘° 2021-01-30 03:20

I am trying to pull from a repository in Github. But I don\'t want to clone the master branch. I want to clone some other branch. When I try git clone ,

相关标签:
4条回答
  • 2021-01-30 03:35

    use git clone --branch <name> possibly adding --single-branch

    as usual you have git clone --help to read details on commands

    0 讨论(0)
  • 2021-01-30 03:36

    Try this:

    git init
    git fetch url-to-repo branchname:refs/remotes/origin/branchname
    

    EDIT

    A better solution:

    git clone -b mybranch --single-branch git://sub.domain.com/repo.git
    
    0 讨论(0)
  • 2021-01-30 03:55
    git clone <url>
    

    clones and creates remote-tracking branches for each branch. If you want to see available branches (after cloning), you type

    git branch -l
    

    To switch to a particular branch after cloning you do:

    git checkout <branchname>
    

    where branchname is the name of the branch :)

    If you want to clone and checkout a specific branch you do

    git clone -b <branchname> <url>
    

    The other commands you mention are for "updating" your current working copy. git pull gets all changes from the remote repository and merges them while git fetchonly gets them without merging.

    0 讨论(0)
  • 2021-01-30 03:58

    If you already cloned the repo and want to contribute to the branch other than master, do this:

    $ git checkout --track origin/<branch-name>
    

    Of course, be sure to specify the right name of the remote (origin in the example above)

    This command will create a new local branch that will track a particular remote branch.

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