简体   繁体   English

捕获当前分支名称并在Windows上使用Git别名将其删除?

[英]Capture current branch name and delete it using Git alias on Windows?

Currently I'm using this alias to fetch master in the background and then switch to it. 目前,我正在使用此别名在后台获取master,然后切换到该别名。 This way Visual Studio works the fastest for me: 通过这种方式,Visual Studio对我而言最快:

[alias]
  fetch-checkout = !git fetch -p && git fetch origin master:master && git checkout master

What I'd like to do on top of that is to capture current branch name and delete it afterwards. 我最想做的是捕获当前分支名称,然后将其删除。

Is it possible on Windows? 在Windows上可以吗?

Since you can't delete a branch you're currently on, you would need to use some kind of temporary storage for the old branch's name. 由于您无法删除当前所在的分支,因此您需要为旧分支的名称使用某种临时存储。 Something like: 就像是:

git rev-parse --abbrev-ref HEAD > tmp.txt && git checkout master && git branch -d `cat tmp.txt` && rm tmp.txt

would work, but you'd need to make sure you're not overwriting anything with the > tmp.txt 可以,但是您需要确保不会使用> tmp.txt覆盖任何> tmp.txt

https://stackoverflow.com/a/12142066/7976758 https://stackoverflow.com/a/12142066/7976758
Q: How to get the current branch name in Git? 问:如何在Git中获取当前的分支名称?
A: git rev-parse --abbrev-ref HEAD A:git rev-parse --abbrev-ref头

[alias]
  fetch-checkout = !curbr=$(git rev-parse --abbrev-ref HEAD) && git fetch -p && git fetch origin master:master && git checkout master && git branch -D $curbr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM