可以在常规的Windows命令提示符下显示当前的git分支名称吗?
让我们说在Windows 7或10上.
我希望能够从PowerShell脚本执行git命令,该脚本与我的git repo不在同一个文件夹中.
首先,我想检查当前的分支,如果它不是主要的,请尝试检查主机和拉主机.
到目前为止我做了什么:
function Get-ScriptDirectory {
Split-Path $script:MyInvocation.MyCommand.Path
}
$currentPath = Get-ScriptDirectory
[string]$Path_GIT = "C:\Program Files\Git\git-cmd.exe"
$gitRepo = $currentPath + "\..\"
$nameCurrentBranch = & $Path_GIT git -C "$gitRepo" rev-parse --abbrev-ref HEAD
Run Code Online (Sandbox Code Playgroud)
$gitRepo 包含包含git repo的文件夹的路径.
我收到错误:
git-cmd.exe : fatal: Cannot change to 'C:\Users\MyName\Documents\Projects\MyProject\
Batchs\.." rev-parse --abbrev-ref HEAD': Invalid argument
At C:\Users\MyName\Documents\Projects\MyProject\Batchs\Publish.ps1:64 char:22
+ ... entBranch = & $Path_GIT git -C "$gitRepo" rev-parse --abbrev-ref HEAD ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (fatal: Cannot c...nvalid argument:String) … 如果我创建一个新分支并尝试推送它,则会被告知必须明确说出上游分支的名称。
> git checkout -b feature/long-branch-name-I-dont-want-to-have-to-type-out
Switched to a new branch 'feature/long-branch-name-I-dont-want-to-have-to-type-out'
> git push
fatal: The current branch feature/long-branch-name-I-dont-want-to-have-to-type-out has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/long-branch-name-I-dont-want-to-have-to-type-out
Run Code Online (Sandbox Code Playgroud)
有什么方法可以不必输入上游分支的名称吗?实际上,我一直希望它在服务器上与本地名称相同。
有什么方法可以执行类似的操作 git push --set-upstream <current_branch_name>,而与当前分支名称的名称无关吗?
在 Git Bash 中,存储库会列出当您位于存储库目录中时它们所在的分支。
目前,我正在开发一个项目,该项目将一组存储库编译成一个产品,当我位于包含所有这些存储库的目录中时,能够看到接下来列出的每个存储库的当前分支将非常有帮助当我到它的时候ls。
有没有一种设置或方法可以让 Git Bash 以这种方式运行?也许ls是我不熟悉的标志(尽管这似乎值得怀疑)?
我使用 Vscode,我想知道我的 HEAD 指向哪里分支,
如何像 Bash 一样显示当前分支名称?
我在 Vscode 中使用 WSL(ubuntu)termimal,操作系统是 Windows 10
谢谢

我使用克隆我的源代码git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git w/.然后我通过执行git checkout <tag name>或指定特定的分支/标记git checkout origin/REL<release number>.有时我会忘记我所在的分支或标签.
在SVN中,我会svn info找出我正在使用的分支/标记(我意识到git具有不同的定义branch,tag但就我的目的而言,它们是相同的).
如何确定我所在的分支/标签?