Reputation: 45941
I know this is a basic question.
Finishing a release, I push master branch to production.
Then, I am working on development branch to add new features.
Now the questions:
Q1: When I push the development branch to staging (on heroku) using git push app-name-staging development:master
, I get the following error. Why? How to fix it?
! [rejected] development -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:app-name-staging.git'
Q2: While working on the development branch, someone finds a bug. I switch to the master branch, and fix the bug. What is the proper way to merge the bug fix made in the master branch into the dev branch, without changing the master branch?
Thanks.
Upvotes: 0
Views: 212
Reputation: 128899
In reverse order, because 2 is simpler:
git checkout dev
git merge master
That's it. It doesn't change master at all. It just merges all changes made on master into your dev branch.
For the other, the non-fast-forward error is telling you that there are commits in the branch you're pushing to that would be overwritten if your push were to succeed. Typically, it happens when two people are working in the same branch. Suppose you and I both have commit A, and we both start working on it in the same branch. You create commit B1, and I create B2. Both have A as their parent. Say you push first, so now the remote branch has A---B1. Locally, I have A---B2. If I were to push my branch, then A---B2 is what would be on the remote, so your commit would be lost. This is where I'd get the non-fast-forward error. The correct way to resolve this is to first pull to get the changes that someone else put out there, and then push the result. In the example, If I pulled, I'd end up with:
C
/ \
B1 B2
\ /
A
Specifically, git first grabs your B1, which is a child of A and sibling of B2, then it merged B1 and B2 together to form C. Now I can push C back to the remote without losing any history because your B1 is correctly represented there.
Upvotes: 3