Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.
I am now
For me working solution is:
ON REMOTE:
git checkout -b some_tmp_name
ON LOCAL:
git push
ON REMOTE:
git checkout master
git branch -d some_tmp_name
But this is not the real solution it's just workaround.
Just in case someone finds it useful. For me it was a git server permissions issue. I checked out the project from the beggining and push a simple file and then I got the "Push rejected: Push to origin/master was rejected"
Pull and push again:
git pull; git push
Push into different branch:
git push origin master:foo
and merge it on remote (either by git
or pull-request)
git merge foo
Force it (not recommended unless you deliberately changed commits via rebase
):
git push origin master -f
If still refused, disable denyCurrentBranch
on remote repository:
git config receive.denyCurrentBranch ignore
You will need to change the config file on the remote server once you have created empty(bare) repository, say
root@development:/home/git/repository/my-project# cat config
there you will see
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
You will make this bare to false to true and I removed logallrefupdates = true (not sure of its use!)
to
[core]
repositoryformatversion = 0
filemode = true
bare = true
You may test following
$ git remote show origin
* remote origin
Fetch URL: my-portal@development:/home/XYZ/repository/XYZ
Push URL: my-portal@development:/home/XYZ/repository/XYZ
HEAD branch: (unknown)
This HEAD branch: (unknown) will be shown if you are unable to PUSH. So if the HEAD branch is unknow, you should change bare to true and after push successful you can reuse the
git remote show origin
and you will see
HEAD branch: master
With a few setup steps you can easily deploy changes to your website using a one-liner like
git push production
Which is nice and simple, and you don't have to log into the remote server and do a pull or anything. Note that this will work best if you don't use your production checkout as a working branch! (The OP was working within a slightly different context, and I think @Robert Gould's solution addressed it well. This solution is more appropriate for deployment to a remote server.)
First you need to set up a bare repository somewhere on your server, outside of your webroot.
mkdir mywebsite.git
cd mywebsite.git
git init --bare
Then create file hooks/post-receive
:
#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
And make the file executable:
chmod +x hooks/post-receive
On your local machine,
git remote add production git@myserver.com:mywebsite.git
git push production +master:refs/heads/master
All set! Now in the future you can use git push production
to deploy your changes!
Credit for this solution goes to http://sebduggan.com/blog/deploy-your-website-changes-using-git/. Look there for a more detailed explanation of what's going on.
Using this to push it to the remote upstream branch solved this issue for me:
git push <remote> master:origin/master
The remote had no access to the upstream repo so this was a good way to get the latest changes into that remote