I have two terminals, each focused on a separate copy of the same git repository, both on HEAD of the 'master' branch
In terminal 1, I make a change, commit it and push it.
In terminal 2, I perform a pull. This actually performs a merge (even though I have not changed anything in this instance).
If I now do a 'git status' in terminal 2, it says that it is ahead of origin/master by one commit and that I should perform a push to 'publish your local commits'.
I have two questions:
Why does it perform a merge? Why does it not just retrieve the latest version?
In my small brain, the instance in terminal 2 is now up to date with master. It is not ahead; it is the same. Why does Git consider this to be ahead? It seems (at best) counter-intuitive and (at worse) just plain wrong.
As a side note, if I then go on to push terminal 2's instance (after the pull), then this will add another commit to the repository history, and (according to 'log --graph' the commit from terminal 1 seems to now be treated as a branch of some sort). This all seems, frankly, plain wrong.
Edited to show example;-
Terminal 1
> cd ~/t1
> git clone git@server:test/test-repository-1.git
> cd test-repository-1
Terminal 2
> cd ~/t2/
> git clone git@server:test/test-repository-1.git
> cd test-repository-1
Terminal 1
> vim rich1 [...edit an exiting file 'rich1'...]
> git add -u
> git commit
> git push
[Note: No odd/unexpected output from any of the above]
Terminal 2
> git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From server:test-repository-1
75ec9a3..ef01990 master -> origin/master
Merge made by the 'recursive' strategy.
rich1 | 1 +
1 file changed, 1 insertion(+)
> git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
If I then continue to perform a push from Terminal 2, I get this;-
> git log --graph
* 826660c (HEAD -> master, origin/master, origin/HEAD) Merge branch 'master' of server:test-repository-1
|\ [this is the commit from Terminal 2]
| * ef01990 comment [this was the commit from Terminal 1]
|/
| M rich1
<snip>
To answer the request by eftshift0 in the comments, I repeated the above and...;-
Terminal 1
<as previous>
> git commit
[master 3f513fe] comment
1 file changed, 1 deletion(-)
Terminal 2
> git fetch -a; git log --graph --oneline HEAD @{u}
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From server:test-repository-1
826660c..3f513fe master -> origin/master
* 3f513fe comment
* 826660c Merge branch 'master' of server1:test-repository-1
|\
| * ef01990 comment
|/
* 75ec9a3 added text to rich1
* 66b1c1b Modified README and added rich1
* a2af0fd comment 1
* 867b6fd mmreadme added
* db4b74f added empty readme file
> git pull
Merge made by the 'recursive' strategy.
rich1 | 1 -
1 file changed, 1 deletion(-)
> git log --graph --oneline HEAD @{u}
* 2597513 Merge branch 'master' of spc-git-dev01:git-training/test-repository-1
|\
| * 3f513fe comment
|/
* 826660c Merge branch 'master' of spc-git-dev01:git-training/test-repository-1
|\
| * ef01990 comment
|/
* 75ec9a3 added text to rich1
* 66b1c1b Modified README and added rich1
* a2af0fd comment 1
* 867b6fd mmreadme added
* db4b74f added empty readme file
Further edit....
> git config -l
user.email=<snip>
user.name=<snip>
url.https:<snip>
color.ui=true
color.status=true
color.brnch=true
alias.co=checkout
alias.br=branch
alias.dt=difftool
alias.rem=remote
merge.conflictstyle=diff3
merge.tool=vimdiff
merge.ff=false
mergetool.diffconflicts.cmd=nvim -c DiffConflictsWithHistory "$MERGED" "$BASE" "$LOCAL" "$REMOTE"
mergetool.diffconflicts.trustexitcode=true
mergetool.keepbackup=true
mergetool.vimdiff.cmd=nvim -d $MERGED $LOCAL $BASE $REMOTE -c 'wincmd J'
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=<snip>:test-repository-1.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
> git config --global -l
user.email=<snip>
user.name=<snip>
url.https:<snip>
color.ui=true
color.status=true
color.brnch=true
alias.co=checkout
alias.br=branch
alias.dt=difftool
alias.rem=remote
merge.conflictstyle=diff3
merge.tool=vimdiff
merge.ff=false
mergetool.diffconflicts.cmd=nvim -c DiffConflictsWithHistory "$MERGED" "$BASE" "$LOCAL" "$REMOTE"
mergetool.diffconflicts.trustexitcode=true
mergetool.keepbackup=true
mergetool.vimdiff.cmd=nvim -d $MERGED $LOCAL $BASE $REMOTE -c 'wincmd J'