简体   繁体   中英

git - remote: fatal: you are on a branch yet to be born, using post-receive hook

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 the beta branch should sync with beta.tinyweatherstation.com , and I have successfully gotten the post-receive hook working with the master branch, but when this for the beta branch:

git remote add live_beta ssh://wesley@tinyweatherstation.com/var/www/tinyweatherstation.com.git
git push live_beta +beta:refs/heads/beta

I get the error:

    Enter passphrase for key '/c/Users/WesleyN/.ssh/id_rsa':
Counting objects: 999, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (967/967), done.
Writing objects: 100% (999/999), 5.04 MiB | 529.00 KiB/s, done.
Total 999 (delta 360), reused 0 (delta 0)
remote: Resolving deltas: 100% (360/360), done.
remote: fatal: You are on a branch yet to be born
To ssh://tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git
 * [new branch]      beta -> beta

The post receive hook looks like this...

#!/bin/sh GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f

I have commited to this branch (beta) so I know it is there, so please help...

  • 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: eg, 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, ie, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM