How can I push a local Git branch to a remote with a different name easily?

問題:

I've been wondering if there's an easy way to push and pull a local branch with a remote branch with a different name without always specifying both names.我一直想知道是否有一種簡單的方法可以使用不同名稱的遠程分支推送和拉取本地分支,而無需始終指定兩個名稱。

For example:例如:

$ git clone myrepo.git
$ git checkout -b newb
$ ...
$ git commit -m "Some change"
$ git push origin newb:remote_branch_name

Now if someone updates remote_branch_name, I can:現在,如果有人更新 remote_branch_name,我可以:

$ git pull

And everything is merged / fast-forwarded.一切都被合併/快進。 However, if I make changes in my local "newb", I can't:但是,如果我在本地“newb”中進行更改,則不能:

$ git push

Instead, I have to:相反,我必須:

% git push origin newb:remote_branch_name

Seems a little silly.好像有點傻。 If git-pull uses git-config branch.newb.merge to determine where to pull from, why couldn't git-push have a similar config option?如果git-pull使用git-config branch.newb.merge來確定從哪裏拉,爲什麼git-push不能有類似的配置選項? Is there a nice shortcut for this or should I just continue the long way?對此有什麼好的捷徑,還是我應該繼續走很長的路?


解決方案:

參考一: https://en.stackoom.com/question/O4vF
參考二: https://stackoom.com/question/O4vF
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章