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:
And 2 remotes:
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.
Whats the difference between push , commit & fetch ,merge. Git commit basically “records changes to the local repository” while git push “updates remote refs along with associated objects”.
Once the merge is done, make sure to do a git push, to push your changes to the remote repository.
Always Pull Before a Push Doing so will ensure that your local copy is in sync with the remote repository. Remember, other people have been pushing to the remote copy, and if you push before syncing up, you could end up with multiple heads or merge conflicts when you push.
Merging Branches to Remote Repository Before you can push the branch code in the remote repository, you set the remote repository as the upstream branch using the git push command. This command simultaneously sets the upstream branch and pushes the branch contents to the remote repository.
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 to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file---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 your production
production
, that is local/production
is behind then either rebase your local/production
on production
(or merge production
on local/production
)merge
or cherry-pick
your commits to production
and push the changes with git push origin production:production
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With