I cannot find any of the files on my remote repo.
When you push to a remote repo in Git, it does not update the working copy of that remote repo. This means that the working copy will be out of sync with the last version that you pushed. To avoid this confusion, it is recommended to only push to bare repos; repos that do not have a working copy. The reason is that if anything in the working copy has changed, you will not have a chance to be warned about this and perform a merge, because you are pushing to a remote repo.
Generally, the only way you should be modifying a working copy is from within it, such as doing a pull or checkout from within that working copy. If you want a copy of your code to be checked out somewhere on your server automatically when you push, you should set up a post-receive hook that will then go a git pull
into a repository that has a working copy.
You shouldn't have created a 'standard' git repo on the remote host, as Brian Campbell noted. What you should do:
copy all the files you wish to place under version control to a directory on your local machine.
delete them and their containing directory on the remote host.
still on the remote host create a new directory called projectname.git (substitute a meaningful name for projectname
), cd into it, and run git init --bare
on your local machine, in the directory in which you've placed your files:
git init
to initialise a git repogit add .
to add all files and sub-directoriesgit commit -m "Initial commit"
[master agd27c9] Initial commit
git remote add origin ssh://hostaddress/path/to/dir/projectname.git
(you may have to modify this slightly, if you usually access your remote host using ssh://user@hostaddress, for instance)git push origin master
Counting objects ...
Delta compression ...
Writing objects ...
Total ...
To ssh:// ...
git config branch.master.remote origin && git config branch.master.merge refs/heads/master
I have a similar use case at work: desiring a 'pristine' home directory on a number of servers where I check processes, monitor logs, etc. - without having to change every single one of them when I add a new command, alias, script, etc. Learning from the existing answers here I solved like this:
To keep them up to date I added the following git alias to help me out with updating all my remote working copies in a single command:
[alias]
pushall = "!for remote in myremote{1..10}; do git push ${remote} master; ssh ${remote} git reset --hard; done"
Now when a new remote is provisioned - I rsync my $HOME directory from an existing remote to the new one, then add my new machine to the alias above. Running 'git pushall' after making a change (say after adding a handy new script to look at logs) will then update all the remote working copies with a pristine copy of what I want my (remote) $HOME directory to be. No more updating every single remote by hand!
Note: the double quotes around the entire alias are important here otherwise the semi-colon will bite you
Thanks to others for existing answers that helped me get this working.