I have my git repository on a linux located on the company server. I ssh into my linux machine and edit files there.


This method is great until I have a good connection to the server. in case of slow connection or even not having a connection I can't access my work and I am not able to do the job.

Potential Solution

Maybe I can copy my files from linux server to my local machine disk and then run an script that listen to changes made in my local files and mirror it to my remote server.

  • I am using Git, any solution should cover git files too.
  • In case I'm losing my connection I should be able to continue my work on local files and as soon as connection established script should mirror my changes to remote server.
  • My machine runs Mac OSX Lion.
  • 2
    Is there a reason you don't just keep a clone of the git repo locally and then git push to the Linux machine? – Jodie C Jun 11 '12 at 3:44
  • I want to have a mirror of files and git info locally. I don't want to touch the git – Mohsen Jun 11 '12 at 3:50
  • 1
    That's what git clone is for: to mirror a git repository so you can make your own changes without disturbing the remote git repository. But in your case you would git push back to your Linux server when you were done. – Jodie C Jun 11 '12 at 4:01
  • I see my changes from an URL that pointing to my server. Pushing manually wont work – Mohsen Jun 11 '12 at 4:18
  • Sound like a similar problem to this one stackoverflow.com/questions/4948190/… – Johan Jun 11 '12 at 5:04

I'm not entirely sure from the way the question was phrased, but it sounds to me like you might be experiencing some trouble moving from a non distributed version control system (svn, csv, etc.) to a distributed one like git.

As it turns out, you get the functionality you want for free in Git! Simply clone your git repo to the computer you want to work from (git clone <remote-repo>), work as normal (code, git add, git commit, rinse and repeat), and then push back to the remote repo when you're done and have a working internet connection (git push origin master or whatever your remote / branch is called if you didn't go with the defaults). Git downloads a full copy of the repo, including all history, by default; so not having an internet connection shouldn't matter. You can just keep working and sync up with your remote machine when the internet comes back on.

If you're looking for a way to automatically push every time a commit is made, check out git hooks. The post commit hook is probably what you want. Just navigate to the .git/hooks directory inside your git repo and rename the file post-commit.sample to post-commit, or create it and make sure it's executable (chmod +x post-commit) if it doesn't exist. Now anything you put into this script will be executed right after you make a commit, for instance, you seem to want:

git push origin master

You could also use the post-receive hook on the remote machine to do something every time it receives a push from your local repo.

EDIT: In a comment you stated that "pushing manually won't work"; however, git supports pushing via SSH, which is probably how you're managing your server anyways. If not, it can also push via FTP (shudder) and other protocols including HTTP[S] if you configure your server properly. You should probably look into using git this way, as this is how it was designed to be used.


The Right Way to do this is with pulling/pushing from the server. The question is, how can you automate this? Well, with a little bit of work, you could throw together something that auto-pushed to a separate branch on the server everytime a file is changed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.