Що git remote -v showповертається, коли йдеться про походження?
Якщо джерело вказує на github, статус повинен бути актуальним, а не перед будь-яким віддаленим репо. Принаймні, з Git1.6.5 я використовую для швидкого тестування.
У будь-якому випадку, щоб цього уникнути, чітко визначте віддалене репо головного відділення:
$ git config branch.master.remote yourGitHubRepo.git
потім a git pull origin master, за яким слідує a, git statusповинні повернути статус чистого стану (без попередньої).
Чому? оскільки master fetch origin master (включений до майстра початкового джерела git pull) не просто оновлюється FETCH_HEAD(як пояснює Чарльз Бейлі у своїй відповіді ), але й оновлює "віддалену головну гілку" у вашому локальному сховищі Git.
У такому випадку ваш локальний майстер, здається, вже не випереджав віддаленого майстра.
Я можу перевірити це за допомогою git1.6.5:
Спочатку я створюю робоче репо:
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, створюючи оголене репо (таке, яке може приймати push з будь-якого місця)
PS D:\git\tests\pullahead\workrepo> cd ..
PS D:\git\tests\pullahead> git clone --bare workrepo github
Я додаю модифікацію до мого робочого репо, що я натискаю на репозиторій 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 згадує майстер geing попереду ' 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.
git pushтакож, здається, це вирішить (звітування "все в курсі").