I am starting with Git, so I feel that this question could be the newbiest question of day because this task is so simple, but it’s causing a terrible headache..
I have 2 local branches:
- master
- local/production
And 2 remotes:
- master
- production
I need to pass local changes to production. So, my workflow was:
git checkout local/production
git merge master
git commit
git push
git merge:
Seems Work fine, it detected all differences.
git commit:
On branch local/production
Your branch is ahead of ‘origin/production’ by 2 commits.
nothing to commit (working directory clean)
And git push:
Everything up-to-date
So that’s all, I couldn’t push my changes to remote repository.
Root cause: To cut the explanation short, it appears to me that your
local/productionis not trackingorigin/production. You can check this withgit branch -avv.About
git push: Note thatgit pushwithout arguments will update all the remote branches that have updated in your local tracking branches (from thegit-push(1)manual page):Because the result of simple
git pushis 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:If you want
local/productionto trackorigin/production, you can make thelocal/productiontracking branch fororigin/productionusing option-u:(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/productionhere. Why not justproduction? I am suspecting you already haveproductiontrackingorigin/productionand maybe uselocal/productionfor you local development. In this case a reasonable work flow is like this:git pull origin production:productionto pull the changes to yourproductionproduction, that islocal/productionis behind then either rebase yourlocal/productiononproduction(or mergeproductiononlocal/production)mergeorcherry-pickyour commits toproductionand push the changes withgit push origin production:production.