There are three machines: Server, Working machine, home machine. The server hosts a git repository. And eventually all codes will end up to the server.
Working machine is where i do most of my daily development, and the changes will be pushed to the server.
Occasionally, i also do coding at home. And sometimes i would like to push changes to the server directly. and sometimes i would like to push them to my working machine, and then continue working on the next day.
Of course i can also create a temp feature branch on the server and then checkout that branch on my working machine the next day. But that's not what i want. I want to push them directly to my working machine.
I am showing do a demo from scratch:
On the server side:
Setting up a reposotory:
mkdir project.git cd project.git git --bare init
On working machine:
git clone git@gitserver:/opt/git/project.git cd project # Do daily commits, pulls and pushes, nothing special. ...
On home machine
git clone git@gitserver:/opt/git/project.git cd project
now you already have a remote location called "origin", and your local master is pointing to "origin/master".
Then add another remote, which is your working machine:
git remote add working_machine username@working-machine:/your/path/to/project
setup a remote tracking branch that tracks "working_machine/master":
git checkout -b working_master working_machine/master
so now you have
master -> origin/master working_master -> working_machine/master
you can push to either "origin/master" or "working_mashine/master" by
git checkout master # some commits git push origin master git checkout working_master # some commits git push working_machine master
Or push some feature branches
git checkout feature1 git push -u origin feature1 git checkout feature2 git push -u working_machine feature2
remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsist ent remote: error: with what you pushed, and will require 'git reset --hard' to matc h remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable t remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in som remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, se remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
You need to make sure that the branch that you are going to push to is not checked out on the remote machine.
You asked me to pull without telling me which branch you want to merge with, and 'branch.aa.merge' in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. 'git pull <repository> <refspec>'). See git-pull(1) for details. If you often merge with the same branch, you may want to use something like the following in your configuration file: [branch "aa"] remote = <nickname> merge = <remote-ref> [remote "<nickname>"] url = <url> fetch = <refspec> See git-config(1) for details.
make sure that you have set the upstream tracking branch:
git branch --set-upstream feature origin/feature