git branch
Git push branch from one remote to another?
A quick test making some temporary repositories shows you can construct a refspec that can do this:
$ git push rorg origin/one:refs/heads/one
Counting objects: 5, done.
Writing objects: 100% (3/3), 240 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/rorg
* [new branch] origin/one -> one
So origin/BRANCHNAME:refs/heads/BRANCHNAME
Checking in my rorg
remote:
- Clone一个本地干净的库 或者 使用你本地的一个库
- 命令行新增一个remote 叫azure
- 将remote/origin中的所有分支全部推到azure中
- git push azure refs/remotes/origin/*:refs/heads/* //make sure the previous remote name is origin
- 使用同样的方法将tags都推到azure中
- git push azure refs/tags/*:refs/tags/*
过滤分支
git branch -a --list 'o*/chuck/*'
在过滤远程分支的时候,remote name也在过滤里面,pattern可以限制remote name。
remotes/origin/chuck/configuration
remotes/origin/chuck/configuration-uk6.3
remotes/origin/chuck/master
What is the format of <pattern> in git-branch --list
Quoting from that same manual page you linked:
If
--list
is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted with an asterisk. Option-r
causes the remote-tracking branches to be listed, and option-a
shows both local and remote branches. If a<pattern>
is given, it is used as a shell wildcard to restrict the output to matching branches. If multiple patterns are given, a branch is shown if it matches any of the patterns. Note that when providing a<pattern>
, you must use--list
; otherwise the command is interpreted as branch creation.
So the answer, at least according to the documentation, is that "it is used as a shell wildcard". This assumes, of course, that you know what the phrase "shell wildcard" means—and more importantly, it's wrong, since a straight shell wildcard would not match across the /
.
The documentation should say something like: "The pattern acts much like a shell wildcard / glob pattern, except that slashes are not treated specially, so that a*b
matches both accb
and ac/cb
, and a[bc/]*
matches all of a/d
, abcd
, ac/cb
, and accb
."
Examples:
$ git branch -a
a/d
abcd
ac/cb
accb
* master
$ git branch --list 'a*b'
ac/cb
accb
$ git branch --list 'a[bc/]*'
a/d
abcd
ac/cb
accb
$
How do you stop tracking a remote branch in Git?
As mentioned in Yoshua Wuyts' answer, using git branch
:
git branch --unset-upstream
Other options:
You don't have to delete your local branch.
Simply delete the local branch that is tracking the remote branch:
git branch -d -r origin/<remote branch name>
-r, --remotes
tells git to delete the remote-tracking branch (i.e., delete the branch set to track the remote branch). This will not delete the branch on the remote repo!
See "Having a hard time understanding git-fetch"
there's no such concept of local tracking branches, only remote tracking branches.
Soorigin/master
is a remote tracking branch formaster
in theorigin
repo
As mentioned in Dobes Vandermeer's answer, you also need to reset the configuration associated to the local branch:
git config --unset branch.<branch>.remote
git config --unset branch.<branch>.merge
Remove the upstream information for
<branchname>
.
If no branch is specified it defaults to the current branch.
(git 1.8+, Oct. 2012, commit b84869e by Carlos Martín Nieto (carlosmn
))
That will make any push/pull completely unaware of origin/<remote branch name>
.
Find out which remote branch a local branch is tracking
回答1
Here is a command that gives you all tracking branches (configured for 'pull'), see:
$ git branch -vv
main aaf02f0 [main/master: ahead 25] Some other commit
* master add0a03 [jdsumsion/master] Some commit
You have to wade through the SHA and any long-wrapping commit messages, but it's quick to type and I get the tracking branches aligned vertically in the 3rd column.
If you need info on both 'pull' and 'push' configuration per branch, see the other answer on git remote show origin
.
Update
Starting in git version 1.8.5 you can show the upstream branch with git status
and git status -sb
https://git-scm.com/docs/git-status
-s--short
Give the output in the short-format.
-b--branch
Show the branch and tracking info even in short-format.
git branch -vv | grep 'BRANCH_NAME'
git branch -vv
: This part will show all local branches along with their upstream branch .
grep 'BRANCH_NAME'
: It will filter the current branch from the branch list.
作者: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:你的「微服务管家」又秀新绝活了
2015-10-14 C#中this在构造函数时的使用
2015-10-14 Monitor vs WaitHandle