0
0

git upstrreamnit

Posted at

upstrreamとは

ローカルブランチが関連付けられたリモートブランチのことを指します。
具体的には、ローカルブランチに対するデフォルトのリモートブランチとして機能し、git pushgit pullの操作で使用されるブランチです。
この設定により、Gitはどのリモートブランチに対して変更を送るべきか、またはどこから変更を取得すべきかを理解します。

upstreamの役割

デフォルトの同期先:
ローカルブランチに対する操作(特にプッシュやプル)を実行する際、upstreamブランチはデフォルトの同期先として機能します。

データの整合性:
upstreamブランチの設定により、ローカルブランチとリモートブランチ間のデータ整合性を維持することが容易になります。

エラー内容

fatal: The current branch <feature_1> has no upstream branch.
To push the current branch and set the remote as upstream, use        

git push --set-upstream origin <feature_1>

To have this happen automatically for branches without a tracking     
upstream, see 'push.autoSetupRemote' in 'git help config'.

解決策

基本的にはローカルブランチと同じブランチ名を関連付けるでよい。

  • 明示的に上流ブランチを設定(2つは同義)
$ git branch <ローカルブランチ名> -u <リモートブランチ名>
$ git branch <ローカルブランチ名> --set-upstream-to=<リモートブランチ名>
  • ローカルブランチ名を省略すると、自動的に現在のブランチを設定
$ git branch -u <リモートブランチ名>
$ git branch --set-upstream-to=<リモートブランチ名>
  • 自動化する
    新しいローカルブランチをプッシュする際に自動的にupstreamブランチを設定するオプションがあります。
git config --global push.default current

これにより、新しいローカルブランチをリモートにプッシュするときに、
同名のリモートブランチが自動的にupstreamとして設定されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0