git推送本地分支到远端 以及删除远端分支的 命令

时间:2023-12-19 23:13:50

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