简体   繁体   English

当您意外删除本地分支时,如何从远程拉分支?

[英]How to pull a branch from remote when you accidentally deleted local branch?

I have 3 branches and i have pushed all the 3 branches to remote git [ aka bitbucket am using bb]. 我有3个分支,我已将所有3个分支推送到远程git [aka bitbucket我正在使用bb]。 I deleted a branch locally now using git branch -d <branch-name> 我现在使用git branch -d <branch-name>在本地删除了一个分支

I did a git push also . 我也做了一个git push。 But now i want all the branches to be present in my local system. 但是现在我希望所有分支都出现在我的本地系统中。

Since you pushed the branches you can create a local branch that is tracking the remote with: 自从推送分支以来,您可以创建一个本地分支,该分支通过以下方式跟踪远程:

git branch --track <local branch name> <remote branch name>

Your remote branch names will be something origin/foo and you can see the list of them with git branch -r 您的远程分支名称将是一个origin/foo ,您可以使用git branch -r查看它们的列表。

https://www.kernel.org/pub/software/scm/git/docs/git-branch.html https://www.kernel.org/pub/software/scm/git/docs/git-branch.html

For adding all the remotes in one line you can do the following: 要在一行中添加所有遥控器,您可以执行以下操作:

git branch -r | egrep -v "(HEAD|master)" | sed -e "s/origin\///" | xargs -I % git branch --track % origin/%

This gets a list of all the remote branches except HEAD and master. 这将获得除HEAD和master之外的所有远程分支的列表。 Then creates a new local version with the same name that will track the remote. 然后创建一个具有相同名称的新本地版本,该版本将跟踪远程服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当您在另一个本地分支中时,如何从远程进行git pull? - How to do git pull from remote when you are in another local branch? 如何在eclipse中将一个分支从远程拉到本地(更新分支) - How to pull a branch from remote to local in eclipse (update branch) 如何从远程分支“someBranch”拉到本地分支“sonOfSomeBranch”? - How to pull from a remote branch `someBranch` to a local branch `sonOfSomeBranch`? 如何将远程分支拉入新的本地分支 - How to pull a remote branch into a new local branch pull而不是fetch - 意外地将远程master合并到本地分支 - pull instead of fetch - accidentally merged remote master into local branch Git - 如何跟踪从本地分支创建的远程分支? - Git - How to track a remote branch that you created from a local branch? 如何从本地主机(而不是已删除的分支)中提取本地存储库? - How to have my local repo pull from master, not a deleted branch? 当你调用pull down the actual remote branch时,为什么建议在git中创建一个跟踪远程分支的本地分支 - why is it suggested to create a local branch tracking the remote branch in git when you call pull down the actual remote branch 删除了远程分支的本地分支。 如何重新获得本地? - deleted local branch of remote branch. How to reobtain local? Git-从本地和远程恢复已删除的分支 - Git - Recover Deleted branch from local and remote
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM