git推送本地分支到遠端 以及刪除遠端分支的 命令


git推送本地分支到遠端

當前處於master分支,嘗試用了git push origin

warning:
push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'.
To squelch this message and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple' behavior,
which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git)

 

push的時候,指定遠端名稱,然后本地分支名稱:遠端分支名稱

$ git push origin Test:master

將本地的Test分支推送到遠端的master分支

 

 

通過命令刪除遠端分支

之前推送本地的代碼到遠端的時候,遠端的分支名字寫錯了,導致遠端產生了一個新的分支

之前用的git push -f origin Test:mater

$ git push origin :mater
Username for 'https://github.com': chucklu
Password for 'https://chucklu@github.com':
To https://github.com/chucklu/WCFTest.git
- [deleted] mater

 

git push origin :mater

推送一個空白分支到mater上,相當於刪除mater分支

 

這次失誤了,推送的時候,多了一個空格。然后直接就推送了一個新的同名分支到遠端,並且刪除了master分支

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (master)
$ git push chucklu chucklu_master :master
Username for 'https://github.com': chucklu
Password for 'https://chucklu@github.com':
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 765 bytes | 0 bytes/s, done.
Total 8 (delta 6), reused 0 (delta 0)
To https://github.com/chucklu/Hearthstone-Deck-Tracker.git
- [deleted] master
* [new branch] chucklu_master -> chucklu_master

 

補救措施

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (master)
$ git push chucklu chucklu_master:master
Username for 'https://github.com': chucklu
Password for 'https://chucklu@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/chucklu/Hearthstone-Deck-Tracker.git
* [new branch] chucklu_master -> master

 

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (master)
$ git push chucklu :chucklu_master
Username for 'https://github.com': chucklu
Password for 'https://chucklu@github.com':
To https://github.com/chucklu/Hearthstone-Deck-Tracker.git
- [deleted] chucklu_master

 

 

推送的時候分支和遠端分支如果名字一樣,且repository有多個remote,那么git push remoteName

 

如果本地分支的名字和遠端分支名字不一樣,就需要顯式指定了

當前處於要推送的分支上

git push remoteName HEAD:RemoteBranchName

當前不處於要推送的分支上

 

git push remoteName localBranchName:RemoteBranchName

 

更新 2018-07-18

刪除分支的時候,tag和branch重名

https://stackoverflow.com/questions/32927154/delete-a-remote-branch-with-the-same-name-as-tag

You can push the full branch refspec:

git push origin :refs/heads/3.0.0
# shorter:
git push origin :heads/3.0.0

That would reference only a branch, not a tag (refs/tags/3.0.0).

git push origin -d heads/sprint6  刪除分支(不是tag)

 

只push一個tag

https://stackoverflow.com/questions/23212452/how-to-only-push-a-specific-tag-to-remote

You can simply use:

git push origin tag_a

Alternatively (mainly to solve tag/branch name clashes), you could use:

git push origin refs/tags/tag_a

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM