git push succeeded, but remote repository is not updated or synchronized

858 views Asked by At

I'm learning git on my mac os x. I've enabled ssh on my mac, and try to simulate both remote repo and local repo.

I run into the case that after I change my file in local repo, git add/commit/push succeeded, I don't see the change on my remote repo. My steps are like this: Create the remote repo

$cd ~/learn
$mkdir gittest
$cd gittest/
$git init
$git config --global user.name "username"
$git config --global user.email "useremail"
$touch readme
$git add readme
$git commit -m "empty"

OK, everything fine, then in another directory, I did:

$cd ~/learn/client
$git clone trosky@localhost:/Users/trosky/learn/gittest
$cd gittest
$vi readme(add one line)
$git add .
$git commit -m "add line"
$git push origin master:refs/for/master

Seems ok, git push prints:

Counting objects: 3, done.
Writing objects: 100% (3/3), 274 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To x@localhost:/Users/trosky/learn/gittest
 * [new branch]      master -> refs/for/master

$git log

I can see 2 records.

commit e4a3af902d8d3b708509073e4fd2281ab8355cf0
Author: username <useremail>
Date:   Fri Dec 23 20:54:52 2016 +0800

    add line

commit e024e83b1227f8d1e585cad66e7a4f9b3bb12462
Author: username <useremail>
Date:   Fri Dec 23 20:53:18 2016 +0800

    empty

But in the gittest directory, I can only see 1 git log and the file is still empty

$git log
commit e024e83b1227f8d1e585cad66e7a4f9b3bb12462
Author: username <useremail>
Date:   Fri Dec 23 20:53:18 2016 +0800

    empty

This is so weird. I repeated the process several times, each time the same result. Why is that and how to fix?

2

There are 2 answers

0
poke On BEST ANSWER

You’re pushing to refs/for/master, not refs/heads/master so what you pushed will not appear as a “real” branch. Instead, you’re pushing to refs/for/* which is a common refspec from code reviewing tools like Gerrit.

If you’re using one of these tools, you should check whether your push generated a code review item somewhere; or consult the manual to make sure that you’re doing everything correctly.

Otherwise, if you just want to push the master branch, then push correctly to refs/heads/master or just use git push origin master assuming the default configuration for your remote.

1
Lalji Nakum On

After PUSH you have to merge both the repo to move that changes in remote repo.