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
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2014-07-20 C#中的异步编程模式