git remote -v show
起源に関しては何が返されますか?
オリジンがgithubを指している場合、ステータスは最新であり、リモートリポジトリよりも前ではありません。少なくとも、Git1.6.5では、簡単なテストに使用しています。
とにかく、これを回避するには、マスターブランチのリモートリポジトリを明示的に定義します。
$ git config branch.master.remote yourGitHubRepo.git
次に、、のgit pull origin master
後git status
にクリーンステータスを返す必要があります(先にありません)。
なんで?get fetch origin master(git pull origin masterに含まれている)はFETCH_HEAD
(Charles Baileyが彼の回答で説明しているように)更新するだけでなく、ローカルGitリポジトリ内の「リモートマスターブランチ」も更新するためです。
その場合、ローカルマスターはリモートマスターより「進んでいる」ようには見えません。
git1.6.5でこれをテストできます:
まず、workrepoを作成します。
PS D:\git\tests> cd pullahead
PS D:\git\tests\pullahead> git init workrepo
Initialized empty Git repository in D:/git/tests/pullahead/workrepo/.git/
PS D:\git\tests\pullahead> cd workrepo
PS D:\git\tests\pullahead\workrepo> echo firstContent > afile.txt
PS D:\git\tests\pullahead\workrepo> git add -A
PS D:\git\tests\pullahead\workrepo> git commit -m "first commit"
ベアレポジトリ(どこからでもプッシュを受信できるレポジトリ)を作成して、GitHubレポジトリをシミュレートします
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone --bare workrepo github
作業リポジトリにmodifを追加し、それをgithubリポジトリにプッシュします(リモートとして追加)
PS D:\git\tests\pullahead> cd workrepo
PS D:\git\tests\pullahead\workrepo> echo aModif >> afile.txt
PS D:\git\tests\pullahead\workrepo> git ci -a -m "a modif to send to github"
PS D:\git\tests\pullahead\workrepo> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo> git push github
GitHubのクローンを作成し、GitHubにプッシュするいくつかの変更を加えたホームリポジトリを作成します。
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone github homerepo
PS D:\git\tests\pullahead> cd homerepo
PS D:\git\tests\pullahead\homerepo> type afile.txt
firstContent
aModif
PS D:\git\tests\pullahead\homerepo> echo aHomeModif1 >> afile.txt
PS D:\git\tests\pullahead\homerepo> git ci -a -m "a first home modif"
PS D:\git\tests\pullahead\homerepo> echo aHomeModif2 >> afile.txt
PS D:\git\tests\pullahead\homerepo> git ci -a -m "a second home modif"
PS D:\git\tests\pullahead\homerepo> git push github
次に、最初の実験のためにworkrepoのクローンを作成します
PS D:\git\tests\pullahead\workrepo4> cd ..
PS D:\git\tests\pullahead> git clone workrepo workrepo2
Initialized empty Git repository in D:/git/tests/pullahead/workrepo2/.git/
PS D:\git\tests\pullahead> cd workrepo2
PS D:\git\tests\pullahead\workrepo2> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo2> git pull github master
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From d:/git/tests/pullahead/github
* branch master -> FETCH_HEAD
Updating c2763f2..75ad279
Fast forward
afile.txt | Bin 46 -> 98 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
そのリポジトリでは、git statusは、マスターが' origin
'より先に進んでいることを示しています。
PS D:\git\tests\pullahead\workrepo5> git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
しかし、それはorigin
githubではありません。
PS D:\git\tests\pullahead\workrepo2> git remote -v show
github d:/git/tests/pullahead/github (fetch)
github d:/git/tests/pullahead/github (push)
origin D:/git/tests/pullahead/workrepo (fetch)
origin D:/git/tests/pullahead/workrepo (push)
しかし、githubを起源とする(または起源がまったくなく、リモートの「github」が定義されている)リポジトリでシーケンスを繰り返すと、ステータスはクリーンになります。
PS D:\git\tests\pullahead\workrepo2> cd ..
PS D:\git\tests\pullahead> git clone workrepo workrepo4
PS D:\git\tests\pullahead> cd workrepo4
PS D:\git\tests\pullahead\workrepo4> git remote rm origin
PS D:\git\tests\pullahead\workrepo4> git remote add github d:/git/tests/pullahead/github
PS D:\git\tests\pullahead\workrepo4> git pull github master
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From d:/git/tests/pullahead/github
* branch master -> FETCH_HEAD
Updating c2763f2..75ad279
Fast forward
afile.txt | Bin 46 -> 98 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
PS D:\git\tests\pullahead\workrepo4> git status
# On branch master
nothing to commit (working directory clean)
origin
を指しているだけの場合github
、status
git1.6.5ではクリーンになります。
以前のgitには「先行」警告が表示される場合がありますが、とにかく、git config branch.master.remote yourGitHubRepo.git
Gitの初期バージョンであっても、明示的に定義されたものがそれを処理できるはずです。