MEM
MEM

Reputation: 31387

git push files don't get updated remotely

A very common scenario:

We have a bare repository. If the developers do git push from their local machine to the bare repo, and then another developer does git pull they get the local version of the application (files included) updated.

However, from time to time, when a change is made directly (by our host or whatever) on the remote working tree, we end up having different file versions on our local machines, and the remote working tree get's always outdated!

According to this:

https://git.wiki.kernel.org/index.php/GitFaq#non-bare

The push operation is always about propagating the repository history and updating the refs, and never touches the working tree files. In particular, if you push to update the branch that is checked out in a remote repository the files in the work tree will not be updated.

I'm not sure what checked out in a remote repository means. I didn't make any git checkout whatever to switch branches using ssh remotely (if that's what that means).

Anyway, if we do git push, no working tree files gets touched. Ok.

So in order to solve this:

If you are sure what you are doing, you can do a "git reset --hard" on the side you pushed to. Note that this WILL lose ALL changes you made on that side, resetting the working tree to the newest revision you pushed.

"git reset --hard"

I did this, but nothing got changed. It says:

HEAD is now at 45d948a Merge branch 'dev' of /home/blabla/private/repos/blabla_hub into dev

But nothing is changed.

1) How does all developers have the working tree updated if they are only pushing and pulling trough a bare (no working tree) repository ? (Where do the files pass?)

2) Why didn't I get the remote working tree updated as expected ?

Are my questions clear? Please advice.

UPDATE

I'm using a dev and master branch. Both locally and remotely, apart from that, I'm using this schema:

The key idea in this system is that the web site exists on the server as a pair of repositories; a bare repository alongside a conventional repository containing the live site. Two simple Git hooks link the pair, automatically pushing and pulling changes between them.

The two repositories:

Hub is a bare repository. All other repositories will be cloned from this.
Prime is a standard repository, the live web site is served from its working directory.

Using the pair of repositories is simple and flexible. Remote clones with ssh-access can update the live site with a simple git push to Hub. Any files edited directly on the server are instantly mirrored into Hub upon commit.

ref. http://joemaller.com/990/a-web-focused-git-workflow/

Upvotes: 0

Views: 264

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83577

From what I understand, you have at least three repos: local, hub, and www/dev. You do your work with the local repo (make changes, commit, and push to hub). Sometimes the www working tree is modified by the webserver. If you want to keep these changes under version control, you can commit them to the www/dev repo and even push the commit from www/dev to hub. (You might be able to automate this with a cron job. I suggest using the output of git status to determine if you want to make a commit.)

Your original question made it sound like the working copy for the www/dev repo gets out of sync with the www/dev repo itself. After further discussion in chat, it appears that the www/dev repo isn't always up-to-date with the hub repo. You just need to make sure to run git pull in the www/dev repo when necessary (possibly with a hook or some other script).

Upvotes: 1

Related Questions