Brain2xml
Brain2xml

Reputation: 67

Can't get updated file on server after git push

I have a local repo on my laptop and a remote repo on a server.

On laptop:

$ git pull ssh://xxxx@xxxxxxx/home/gittest/ master
$ cat a.php 
<?php
echo 'hello';
?>

so I changed file on laptop

$ vim a.php 
$ cat a.php
<?php
echo 'hello';
echo 'hello2';
?>

and commit it

$ git add a.php
$ git commit -m 'update'
$ git push ssh://xxxx@xxxxxxxx/home/gittest/ master

Now I check the file on server

$ cat a.php
<?php
echo 'hello';
?> 

There's still old version

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   a.php
#

How to make files update on server?

Upvotes: 2

Views: 284

Answers (2)

Nick Volynkin
Nick Volynkin

Reputation: 15109

Why this happens

In Git there's

  • [working tree] Working tree is the files in your project folder.
  • [index] - A snapshot of working tree to save in next commit
  • [repository] - the .git/ folder and everything inside it.

When you run git push, you only update the repository on the remote server. If remote is not a bare repository, it also has a working tree. But it has to be changed by a separate actiion.

How do I check if remote repository really gets updated?

Run git remote show <remote name> to see branch status

How to solve this?

Are you using git for deployment to a server? If so, you need to either:

  • after a push login to REMOTE and there run git checkout master to bring the working tree in accordance with the repo
  • setup a server-side post-recieve git hook to do it for you.

If you don't use git for deployment, why need any files on the remote? In such case it's best to use a bare repository.

Upvotes: 4

GreenAsJade
GreenAsJade

Reputation: 14685

You appear to be pulling from and pushing to a working repository.

This won't work the way you want it to, because pushing updates the respository, but not the working copy.

After the push, the version in your server working copy appears modified, because it is different to the HEAD version in the repository that was updated by the push.

You need a bare repository to share from. You can read about that here among other places.

Upvotes: 4

Related Questions