2016-09-20 29 views
0

如何重置我的所有本地分支,一次就像遠程存儲庫中的分支一樣?如何重新設置git中的所有分支

我在本地存儲庫中有42個分支,但在遠程存儲庫中只有21個分支。我不需要其他分支,我只需要21個分支(在本地和遠程都有相同的名稱)。

我知道

git fetch origin 
git reset --hard origin/master 

但我希望所有21枝一起硬復位的狀態起源,和所有其他分支刪除不在原點。

+0

只需刪除存儲庫並從原始位置克隆一個新存儲庫即可。 –

回答

0

如果您在Unix上,則可以使用shell腳本。

這將首先刪除全部您的本地分支機構,然後從原點創建所有分支機構。

# make sure we are currently on no branch, so every branch can be deleted 
git checkout --detach master 

# delete all local branches 
git branch | grep -v "HEAD detached" | xargs git branch -D 

# re-create all branches from origin 
while read b; do git branch ${b#origin/} $b; done < <(git branch -r | grep 'origin/') 

# check out the new master 
git checkout master 
相關問題