我的主分支和开发分支在GitHub上被远程跟踪。如何克隆这两个分支?


当前回答

我试图找出如何删除我在本地删除的远程分支。起源不是我的,我不想经历重新克隆一切的麻烦。

这对我有用:

假设您需要在本地重新创建分支:

git checkout -b recreated-branch-name
git branch -a (to list remote branches)
git rebase remotes/remote-origin/recreated-branch-name

因此,如果我从gituser/master分支到sjp,然后将其分支到sjp/mynewbranch,则如下所示:

$ git checkout -b mynewbranch

$ git branch -a
  master
  remotes/sjp/master
  remotes/sjp/mynewbranch

$ git fetch (habit to always do before)

$ git rebase remotes/sjp/mynewbranch

其他回答

每当我需要推倒所有的树枝时,我都会这样做。来自Linkedin Learning的Ray Villalobos。尝试克隆所有分支,包括提交:

mkdir -p -- newproject_folder
cd newproject_folder
git clone --mirror https://github.com/USER_NAME/RepositoryName.git .git
git config --bool core.bare false
git reset --hard

我认为这样做很有效:

mkdir YourRepo
cd YourRepo
git init --bare .git                       # create a bare repo
git remote add origin REMOTE_URL           # add a remote
git fetch origin refs/heads/*:refs/heads/* # fetch heads
git fetch origin refs/tags/*:refs/tags/*   # fetch tags
git init                                   # reinit work tree
git checkout master                        # checkout a branch

到目前为止,这对我有效。

这个Bash脚本帮助了我:

#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
    git branch --track "${branch##*/}" "$branch"
done

它将为所有远程分支创建跟踪分支,除了master(您可能从原始clone命令中得到)。我想你可能还需要

git fetch --all
git pull --all

当然

一行:gitbranch-a|grep-vHEAD|perl-ne'chomp($_);s |^\*?\s*||;如果(m|(.+)/(.+)|&&not$d{$2}){print qq(git branch--track$2$1/$2\n)}否则{$d{$_}=1}‘|csh-xfs像往常一样:在复制rm-rf宇宙之前,在您的设置中进行测试一行的积分归用户cfi

这并不太复杂。非常简单明了的步骤如下:;

gitfetchorigin:这将把所有远程分支带到本地。

gitbranch-a:这将显示所有远程分支。

git checkout--跟踪origin/<要签出的分支>

通过以下命令验证您是否在所需的分支中;

git branch

输出将是这样的;

*your current branch
some branch2
some branch3

请注意表示当前分支的*符号。

gitclone--原始repo上的镜像很好地实现了这一点。

git clone --mirror /path/to/original.git
git remote set-url origin /path/to/new-repo.git
git push -u origin