4

これは、ローカルブランチが追跡しているリモートブランチを見つけることではありません 。複数のリモートがある場合は、それらすべてに「マスター」が含まれている可能性があります。 マスターを返しますが、私が使用しているマスターブランチがremoteFooにあるのかremoteBarにあるのかわかりません。たとえば、次のようにします。git branch

git clone someRepo.git
cd someRepo
git remote add anotherRemote otherremoteURL

その後、git remoteショー

someRepo
anotherRemote

どちらの場合も、「マスター」と言うことができますgit checkout -b master someRepo/master。最初の部分である「someRepo」または「anotherRemote」を取り戻すにはどうすればよいですか?git checkout -b master anotherRemote/mastergit branch

私が使用できると思うかもしれませんgit remote showが、引数、つまり情報が必要なリモートの名前が必要です。

$ git remote show origin
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git remote show
someRepo
anotherRemote

git branch私は現在何が起こっているのかを知ることができます:

$ git branch
  hold
* master
  old-stuff
  refactor

git remoteただし、出力には「*」はありません。

4

3 に答える 3

13

情報を詳細に表示するには、以下でこれらを試してみてください。

git remote -v
git remote -v show origin

以下の出力例:

dmasi@:/var/www/pirate_booty$ git remote -v
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (fetch)
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (push)

dmasi@:/var/www/pirate_booty$ git remote -v show origin
* remote origin
  Fetch URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  Push  URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
于 2012-09-27T03:02:25.513 に答える
9

git status -sb理解しやすく、覚えやすいようです。

-sGive the output intheshort-formatの略です

bブランチと追跡情報を表示します。

参照:https ://git-scm.com/docs/git-status#git-status--s

于 2018-05-31T18:01:37.497 に答える
2

これは、ここで同様の質問に答えられます。現在のブランチによって追跡されているリモートブランチを取得するには、

git rev-parse --symbolic-full-name --abbrev-ref @{u}
于 2012-09-26T20:13:23.673 に答える