git push does not update files on remote server
I have set up a git repository on my local machine and a bare repository on a linode box. When doing a git push there are no errors but I do not see the file on the remote server. The sequence of commands I followed was below:
abhijat@kangaroo:~$ mkdir dev abhijat@kangaroo:~$ cd dev && git init --bare
On local machine:
krypton:test abhijat$ git init krypton:test abhijat$ vim app.py krypton:test abhijat$ git init Initialized empty Git repository in /Users/abhijat/dev/test/.git/ krypton:test abhijat$ git add . krypton:test abhijat$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: app.py # krypton:test abhijat$ git commit -m 'test first commit' [master (root-commit) 3bee148] test first commit 1 files changed, 16 insertions(+), 0 deletions(-) create mode 100644 app.py krypton:test abhijat$ git remote add origin abhijat@linode:~/dev krypton:test abhijat$ git push -v origin master Pushing to abhijat@linode:~/dev Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 298 bytes, done. Total 2 (delta 1), reused 0 (delta 0) To abhijat@linode:~/dev 01a0e08..2273564 master -> master
But when I check on the linode the file is absent:
abhijat@kangaroo:~/dev$ ls -ltr total 32 drwxr-xr-x 4 abhijat abhijat 4096 Sep 8 10:17 refs drwxr-xr-x 2 abhijat abhijat 4096 Sep 8 10:17 info drwxr-xr-x 2 abhijat abhijat 4096 Sep 8 10:17 hooks -rw-r--r-- 1 abhijat abhijat 73 Sep 8 10:17 description drwxr-xr-x 2 abhijat abhijat 4096 Sep 8 10:17 branches -rw-r--r-- 1 abhijat abhijat 23 Sep 8 10:17 HEAD -rw-r--r-- 1 abhijat abhijat 66 Sep 8 10:57 config drwxr-xr-x 12 abhijat abhijat 4096 Sep 8 11:03 objects abhijat@kangaroo:~/dev$ find . -name app.py abhijat@kangaroo:~/dev$
Am I missing something obvious here? The communication is via ssh and the keys are set up as expected, I can login without a password. However the file does not get copied to the remote server.
Git doesn't work that way on the server side. The files are highly compressed and grouped into chunks so you can't find a particular file.
To test your git server, create another clone in another directory and see if app.py is there.
git clone abhijat@linode:~/dev dev2
If you want to both push to the repo and have the files update, you can create a server-side git hook to checkout the files after they've been pushed. In the server side git /hooks/ directory create a file named post-receive and add the following code:
#!/bin/sh git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
Then give the file proper permissions using chmod +x post-receive
Note: the above code assumes your git directory and deployed files are in different directories. Update the file depending on how you want things configured.
More info & a detailed explanation here: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps