0

追跡されたリモート ブランチを含むローカル リポジトリがあります。新しいブランチをリモートにプッシュできるように、リモートを継承するそのブランチから新しいブランチを作成したいと考えています。

  1. 新しいブランチに入れたいがプッシュしたくない追跡されたローカルブランチにいる間。

    git チェックアウト -b myNewBranch

  2. ブランチをリモートにプッシュする

    git push -u RemoteRepo myNewBranch

現在、最初に新しいブランチのリモートをリモート リポジトリに設定する必要があります。

4

2 に答える 2

2

あなたの質問の言い回しは少しわかりにくいと思いますが、これが正しいかどうか見てみましょう。

  1. repoいくつかの元のマシンから複製されたレポがありますO
  2. では、 を追跡しrepoているローカル ブランチ、つまりonという名前のブランチがあります。あなたはそれに取り組んでいます ( )。borigin/bbOgit checkout b
  3. ここで、新しいブランチ を作成しますnb。に分岐はありませnbO
  4. nb存在しないブランチを追跡したいorigin/nb

origin/nbはまだ存在しないため、最後のステップは (まだ) 不可能です。最初に作成する必要があります(git push -u上記のコマンドのように)。でプッシュすると、-uが作成nbされO、さらに (ローカルで)origin/nbの上流ブランチが作成され、設定さnborigin/nbます。

アップストリームを設定しようとする場合は、次の点に注意してください。

$ git checkout -b nb
... optionally, add various commits here ...
$ git branch --set-upstream-to=origin/nb

エラーが発生します:

error: the requested upstream branch 'origin/nb' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

したがって、代わりに、上記で提案したことを正確に実行する必要があり、「ヒント」に示されています。

$ git checkout -b nb
... optionally, add various commits here ...
$ git push -u origin nb
Counting objects: 10, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (7/7), 633 bytes | 0 bytes/s, done.
Total 7 (delta 2), reused 0 (delta 0)
To ssh://[redacted]
 * [new branch]      nb -> nb
Branch nb set up to track remote branch nb from origin.
于 2013-10-25T19:49:39.433 に答える
0

コミットされていない変更がない場合 ( で確認git status)、2 番目の引数で開始点を指定して、リモート ブランチをチェックアウトします。

git checkout -b mybranch remote/rembranch

mybranchこれにより、 から始まるブランチ が作成されremote/rembranchます。

于 2013-10-25T19:46:29.877 に答える