1

githubから2つのブランチを持つリポジトリのクローンを作成しました:

git clone https://github.com/user/repo
cd repo

私が行うgit branchと、マスターブランチのみが表示されます。それから私はgit branch -aそれがすべての枝を表示することをしました。

master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/develop

それから私はしましたgit checkout develop

Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'

その後、ブランチgit checkout masterに戻ります。master

なぜgit checkout develop違うのですかgit checkout origin/develop(私は頭を外した状態にあると言っています)?

4

3 に答える 3

2

あなたがしたはずです:

git checkout --track -b develop origin/develop
# or
git checkout -t origin/develop

From git checkout: 開始点を指定しない場合、現在から開始されますHEAD(これはmaster、「開発」ブランチが本来あるべき場所から開始されないことを意味します)。

--track オプションについては、「Git: トラッキング ブランチとは」を参照してください。

ローカル リポジトリ内のすべてのリモート ブランチを表示/追跡する場合は、「すべてのリモート git ブランチをローカル ブランチとして追跡する」を参照してください。

git ブランチが現在のブランチである master を返したため、出発点は master でした。
その場で開発を行うとgit checkout、現在のブランチから開始されます。

于 2012-08-03T10:52:36.853 に答える
1

You have not yet created the branch 'develop'. To do this, you need to create a branch that follows the 'origin/develop' branch:

git checkout -b develop origin/develop

The new branch 'develop' is decoupled from the remote branch 'origin/develop'. git does this intentionally: the decoupling allows the branches to vary independently. This is desirable for many reasons, but the two I find most useful are:

  1. You can make a series of changes that are independent of the changes made in the github branch.

  2. Changes made in the github repository are not automatically incorporated into your branch, unless you want them to be. If, for example, 'origin/develop' has a history of being particularly unstable, you may want to control when you incorporate new changes into your local branch 'develop'.

于 2012-08-03T11:05:23.583 に答える
1

git checkout development と言ったとき (リモート " origin" を指定せずに) という名前のローカル ブランチをチェックアウトしようとしていdevelopます。ただし、gitconfig は、その名前のローカル ブランチが見つからない場合、自動的に を探すように設定されていorigin/developます。それを見つけて、developローカルに名前を付けた新しいブランチをチェックアウトし、リモート ブランチを追跡するように自動的に設定しました。

のとき、キャッシュされたアップストリームブランチgit checkout origin/developのコピーをチェックアウトしています。developこれらのブランチは編集できません。これが、git が頭が切り離された状態にあることを示している理由です。

変更を加えたい場合は、ローカルdevelopブランチにコミットしてからgit push.

于 2012-08-03T11:00:38.010 に答える