I am a git newbie so forgive my lack of knowledge but I am not even sure what questions to search google for.
I have a large project only I am working on being developed locally and pushed to a remote webserver with git. The server has a post-receive hook which copies the files for serving with this command:
GIT_WORK_TREE=/my/remote/webserver/base/directory git checkout -f
This has been working fine for months.
Now, I want to build a spinoff and run the new branch on my webserver. I also want to be able to switch back and forth between spinoff and master branches and overwrite the server's code so that I can develop two separate websites simultaneously with only one server. To start, I create a new git branch:
git checkout -b spinoff
I added a line and did a commit:
git commit -a -m 'test'
[spinoff 51f90e9] test
1 file changed, 1 insertion(+)
Now, I am trying to push to the remote branch. This does not work
git push origin master
(everything up to date)
This command pushes as expected but does not copy the files over the web server
git push origin spinoff
Setting it up to push to the master doesn't seem to help:
git branch --set-upstream spinoff origin/master
[edited as pointed out by @Klas Mellbourn] That is the syntax for git 1.7.. If you have git 1.8., the syntax is:
git branch -u origin spinoff
I know I am missing some big key concept here. My guess is that there are two remote repositories as expected but I need to set up something else to copy from the spinoff repo to the webserver.
I think I might have to edit the HEAD file in my remote repository? This currently contains:
ref: refs/heads/master
git push origin master
is giving the message up to date because you are trying to push the branch master, which you haven't changed.
Your hook is doing git checkout -f
, which means it checks out HEAD. When you push spinoff to your repository, HEAD hasn't been changed (it points to master), so nothing is going to be updated.
You need to alter your hook to either look at what refs are being pushed, or designate a specific branch as the one which will get checked out.
Though git isn't very suited as a proper deployment tool see this list for different techniques.