2025.10.10(更新日: 2025.10.11)
      ローカルのブランチ名を変更して、リモートの追跡ブランチを確認する
 
      はじめに
現状、master。
リモートは、main。
ローカルのmasterをmainに変更
git branch -m master mainリモートの追跡ブランチを確認
git remote show origin* remote origin
  Fetch URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  Push  URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  HEAD branch: main
  Remote branches:
    main                       tracked
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote master
  Local ref configured for 'git push':
    main pushes to main (local out of date)- HEAD branch
- Remote branches
- Local branch
- Local ref
について見ていこう。
HEAD branch
* remote origin
  Fetch URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  Push  URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  HEAD branch: main
  Remote branches:
    main                       tracked
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote master
  Local ref configured for 'git push':
    main pushes to main (local out of date)これは、リモートリポジトリでデフォルトブランチとして設定されているブランチのこと。
HEAD branch: mainとは、GitHubのデフォルトブランチがmainということ。

Remote branches
これは、リモートブランチの状況を表している。
* remote origin
  Fetch URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  Push  URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  HEAD branch: main
  Remote branches:
    main                       tracked
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote master
  Local ref configured for 'git push':
    main pushes to main (local out of date)mainブランチが追跡中(tracked)、リモート追跡ブランチのrefs/remotes/origin/masterがリモートに存在しないが参照が残っている(stale)という意味。
mainブランチは、読みやすいようにパスが省略されている。
git remote prune originでリモートに現在は存在しない参照を削除できる。
Local branch
* remote origin
  Fetch URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  Push  URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  HEAD branch: main
  Remote branches:
    main                       tracked
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote master
  Local ref configured for 'git push':
    main pushes to main (local out of date)Local branch configured for ‘git pull’は、git pull用に設定されたローカルのブランチのこと。
main merges with remote masterとあるので、ローカルのmainブランチがリモートのmasterブランチと紐づいている。
Local ref
* remote origin
  Fetch URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  Push  URL: https://github.com/ki-hi-ro/ki-hi-ro.com-2022.git
  HEAD branch: main
  Remote branches:
    main                       tracked
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    main merges with remote master
  Local ref configured for 'git push':
    main pushes to main (local out of date)Local ref configured for ‘git push’は、git push用に設定されたローカル参照のこと。
main pushes to mainとあるので、ローカルのmainブランチからリモートのmainブランチにプッシュされるようになっている。
(local out of date)は、ローカルがリモートよりも古いということ。
git pull origin mainをすれば、ローカルと同じ状態にすることができる。
コメントを残す