Git Hub Clone All Branches At Once

后端 未结 7 1054
时光取名叫无心
时光取名叫无心 2020-12-07 12:19

I\'m trying to clone an entire repository onto my machine using linux. I used

git clone    

I then went into the folder where i

相关标签:
7条回答
  • 2020-12-07 12:39

    To download a full repository, including all branches, use the following command: git clone --mirror <URI>

    This will create a folder called repository.git unless you give it a different name.

    Now, this gets you a full clone of the original repository, but because it's in bare=true mode, you don't have a work tree. Effectively, what you have is the .git folder, including all branches and content. This is a fancy way of saying that you won't have direct access to the files because they're stashed away within the git system (compressed, etc).

    To make this a "normal" git repo, we need to make this clone the .git folder within a new folder, which will be our usual repo folder:

    mkdir <repo folder name> mv repository.git <repo folder name>/.git cd <repo folder name> git checkout master

    Note that there is no single native git command to download all remote branches, so the simplest way is to make sure you have all commits pushed to the origin, and then re-download the whole repository anew using this --mirror option.

    0 讨论(0)
  • 2020-12-07 12:41

    (1) Inside git local repostitory, create a new sh file

    touch getAllBranches.sh
    vi getAllBranches.sh
    

    (2) Insert the below content to getAllBranches.sh file:

    for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
       git branch --track ${branch#remotes/origin/} $branch
    done
    

    (3) Get all branches:

    chmod +x getAllBranches.sh    
    sh getAllBranches.sh
    

    (4) Check result at local repository:

    git branch
    

    For example, I use repository: https://github.com/donhuvy/spring-boot

    As you can see, I have fetched all branches to local machine:

    0 讨论(0)
  • 2020-12-07 12:46

    It's only showing me master and not other branches which were in the remote repository. How do I clone all branches?

    Branches are essentially pointers to commits. When you do a git clone (or a git fetch), you retrieve all of the commits from the remote repository, and all of its branches as well.

    However, git branch does not show remote branches by default. Instead, it shows you your local branches, which may or may not have any relation to branches that exist on the remote. If you run git branch --all, git will report all of the branches it knows about, both local and remote.

    It's worth noting that tags do not operate this way, and there is no distinction between a local and remote tag.

    0 讨论(0)
  • 2020-12-07 12:49

    This isn't too much complicated, very simple and straight forward steps are as follows:

    After cloning the repo, run $ cd myproject

    git branch -a This will show you all the remote branches.

    $ git branch -a
    * master
      remotes/origin/HEAD
      remotes/origin/master
      remotes/origin/v1.0-stable
      remotes/origin/experimental
    

    If you want to work on remote branch, you'll need to create a local tracking branch:

    $ git checkout -b experimental origin/experimental
    

    Verify whether you are in the desired branch by the following command;

    $ git branch
    

    The output will like this;

    *experimental
    master
    some branch2
    some branch3 
    

    Notice the * sign that denotes the current branch.

    0 讨论(0)
  • 2020-12-07 12:54
    git clone --bare <repository url goes here> .git
    

    Then after the repo is clone with all its branches then do the following

    git config --bool core.bare false
    
    git reset --hard
    
    0 讨论(0)
  • 2020-12-07 12:57

    I find this to be the simple solution to clone a git repository and all remote branches:

    # Clone remote repository and all branches
    git clone --mirror https://github.com/test/frontend.git frontend/.git
    
    # Change into frontend directory
    cd frontend
    
    # Update git config
    git config --unset core.bare
    
    # Checkout master branch
    git checkout master
    
    0 讨论(0)
提交回复
热议问题