3

I'm trying to push only my Staging Branch to a bare repo on my staging server with the following command:

git push staging +staging:refs/heads/staging

But I get a fatal error:

you are on a branch yet to be born

If I replace staging with master on the command above it works and deploys my master branch/files to the staging server but my master branch is my production branch and I only want to deploy my staging branch/files.

Can anyone help?

Please bear in mind that I am a designer and not a developer, so a newbie styled answer would be appreciated ;o)

UPDATED

I thought I'd better explain my workflow... just in case it revels some answers to my issue/newbie situation:

  • I have my Origin @ Bitbucket - which holds my entire project
  • I cloned my repo to my local WAMP server for development (where I work on my develop branch)
  • I have three main branches: master (my production branchj / live server), develop (my local branch / WAMP server) and staging (my client acceptance branch / staging server)

I have no problem pushing the entire project to Bitbucket, but I'm struggling to push the files under the staging branch to my staging server.

NB: on my staging server git I'm using a post-receive hook: GIT_WORK_TREE=/path/to/site git checkout -f

I maybe trying to do this completely wrong, but I though I could deploy my code on the staging branch to my staging server?!

Ian
  • 49
  • 1
  • 5

2 Answers2

3

What you should do is:

  • push that branch
  • establish a tracking relationship between the local and the remote one

That is done in one command with:

git push -u staging staging

After that initial first push, and future push can be done with a simple:

git push

See more at "Why do I need to explicitly push a new branch?".

Note that the "best practice" (or at least a better one) is to not name a remote repo reference (staging) and a branch (staging) with the same name, simply to make clearer in those git push command what 'staging' is what.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks VonC, I have added the upstream tracking as suggested but when I push the staging branch (to staging) it says "Everything is up to date". When viewing the staging site, no files have been uploaded - I just get the directory index. – Ian Feb 23 '14 at 07:55
  • @Ian where do you expect files to be updated? `git push` pushes version control data, it doesn't update files. Maybe you want to create a post-receive hook on the server, so that a push will trigger updating your staging site. This answer might help: http://stackoverflow.com/questions/21807396/how-to-set-up-a-git-development-environment-when-youre-testing-remotely/21809083#21809083 – janos Feb 23 '14 at 08:08
  • @janos thanks, I already have a post-receive hook like this: (GIT_WORK_TREE=/path/to/site git checkout -f) so I would expect the test index.html file to appear in the sites root directory. – Ian Feb 23 '14 at 08:28
  • @Ian in the bare repo (server side, where you are pushing to), can you do a `git branch -avvv` and a `git log --graph --oneline --branches --all`, to see if you do see a `staging` branch? – VonC Feb 23 '14 at 09:11
  • @VonC, yep running git branch -avvv show both a master branch and staging branch, with an astrix on my master branch. FYI: I have also updated my original question with some workflow background info, just in case that helps ;o) – Ian Feb 23 '14 at 09:18
  • @Ian then you are good. It simply means the staging branch is at the same commit than the master branch. Now check locally if you are in a branch when you try to push staging, and if staging refers indeed to a commit which isn't yet pushed. – VonC Feb 23 '14 at 09:24
  • @VonC I'm a little confused... did you mean teh staging branch is at the same commit as the master branch? I have also tried locally checking out to the master branch and pushing to staging and checking out to staging branch and pushing to staging, but on both occasion it returns that Everything is up to date (and no files have been deployed on my staging server). – Ian Feb 23 '14 at 11:06
  • @Ian "did you mean the staging branch is at the same commit as the master branch?" yes. On the server side. As for your push attempts, that should indicate that locally, the staging branch references the same commit than, the master branch. – VonC Feb 23 '14 at 11:07
  • @VonC I have also noticed the following when trying to push a new commit to staging: hooks/post-receive: line 2: checkout: command not found. This is my GIT_WORK_TREE=/path/to/site git checkout -f command. Followed by an error: cannot run hooks/post-receive: No such file or directory. Could this be something to do with it? – Ian Feb 23 '14 at 11:08
  • @Ian try to specify also `GIT_DIR=/path/to/bare/repo.git GIT_WORK_TREE=...` in the hook – VonC Feb 23 '14 at 11:18
  • @Ian make also sure that your hook script doesn't contain CRLF eol (only LF) – VonC Feb 23 '14 at 11:21
  • @VonC, thanks for all you help but this still throws up the same error ;o( I guess I'll have to give up and return to deploying my sites without git and get the old pencil and paper out for FTP. Thanks again. – Ian Feb 23 '14 at 11:25
  • @Ian no, I would make this question as resolved, and ask a new one with that exact error message. there is certainly an exact cause for that issue. – VonC Feb 23 '14 at 11:26
  • @VonC FYI: I've fixed my issue (see answer below), thanks for your patience. – Ian Feb 23 '14 at 18:35
1

RESOLVED

The issues I've faced have been resolved fully by updating my git post-receive hook:

FROM GIT_WORK_TREE=/path/to/site git checkout -f

TO GIT_WORK_TREE=/path/to/site git checkout -f staging

Who would have though it would have been such a simple thing ;o)

A big thanks to @VonC for all his help - somehow you led me off down the right path.

Ian
  • 49
  • 1
  • 5