So I am trying to sync to github branches to two parts of my website, theoretically the master branch in my github should be synced with my website tinyweatherstation.com and th
Fetch all repository:
$ git remote add live_beta ssh://wesley@tinyweatherstation.com/var/www/tinyweatherstation.com.git
$ git fetch --all
Create and checkout to beta
branch with remote's beta
branch history ( make sure no local beta
branch exists):
$ git checkout beta
Push to live_beta
repo's beta
branch:
$ git push live_beta beta
The error message comes from the target of the push (the Git there). Given that your post-receive hook is the simple one line expression:
GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f
this means that the Git living at:
ssh://tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git
is, just as the error message says, "on a branch yet to be born". That is, the current branch of that (presumably bare) repository has some name, such as master
, but that branch name does not yet exist.
There are multiple solutions. One is to pick an explicit branch to check out:
GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f beta
That way, this particular Git knows to check out by the name beta
rather than its current branch (again, probably master
—from here on, I'll assume that it is master
) that does not actually exist yet.
Another is to create the branch name master
in that Git repository (on the server at tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git
). There are multiple ways to do this: e.g., you could log in on that machine, navigate to the bare repository, and use git branch
to make the name master
point to any of the existing commits, now that there are some commits in the repository. Or, from your client machine, you could do another git push
, but this time, do one that pushes to the name master
:
client$ git push live_beta master
(assuming you want the server's master
to point to the same commit that your client's master
points-to).
Yet another way is to log in to the server and change the name to which its HEAD
points symbolically, i.e., to change the name of the current branch on the tinyweatherstation.com
server:
server$ git symbolic-ref HEAD refs/heads/beta
Now the git checkout -f
with no branch name will work, because the name beta
refers to the branch you pushed earlier.
Note that using git checkout -f beta
will, as a side effect, set the current branch to beta
.