Git merge and push
Root cause: To cut the explanation short, it appears to me that your local/production
is not tracking origin/production
. You can check this with git branch -avv
.
About git push
: Note that git push
without arguments will update all the remote branches that have updated in your local tracking branches (from the git-push(1)
manual page):
git push ... [<repository> [<refspec>...]]The special refspec : (or +: to allow non-fast-forward updates) directs git topush "matching" branches: for every branch that exists on the local side, theremote side is updated if a branch of the same name already exists on the remoteside. This is the default operation mode if no explicit refspec is found (that isneither on the command line nor in any Push line of the corresponding remotesfile---see below).
Because the result of simple git push
is sometimes little unexpected if forgotten what changes done in local branches, I personally like to explicitly specify which branches I want to push. In your case it seems this is what you want to do:
git push origin local/production:production
If you want local/production
to track origin/production
, you can make the local/production
tracking branch for origin/production
using option -u
:
git push -u origin local/production:production
(only required once). Then you can pull from origin to local/production
.
Executive Summary: you need to understand the concept of tracking branch and the peculiar semantics of git push
.
P.S. I am wondering about your choice of your branch name local/production
here. Why not just production
? I am suspecting you already have production
tracking origin/production
and maybe use local/production
for you local development. In this case a reasonable work flow is like this:
git pull origin production:production
to pull the changes to yourproduction
- If there are new commits in
production
, that islocal/production
is behind then either rebase yourlocal/production
onproduction
(or mergeproduction
onlocal/production
) - the moment you want to push your changes,
merge
orcherry-pick
your commits toproduction
and push the changes withgit push origin production:production
.