While merging a feature branch with the master of GitHub, I have the same scenario and workflow as mentioned in the below question :
Merge non-merged feature branch into another feature branch with Git
I have the master branch. Feature branch1 and the development for feature branch1 is already completed, the code needs to be reviewed and branch should be merged.
Meanwhile, a feature branch branch2 gets created and a piece of work for branch2 depends on code developed in branch1. Since the same code needed in branch2, I have merged and committed the changes in the master branch from branch1 once code review is completed.
Now, I am supposed to get the latest code of master branch in branch2 to start my work in branch2. So, I have merged my feature branch2 again from the master branch.
Is this the correct way to do it, or do I need to delete my feature branch2 and create a new branch again?
Also, since my branch2 was merged from master branch after it was created, when I pushed my changes, that merge was maintained as a history of that branch that will ultimately go to the history of my master branch(as a comment if I do Squash and merge), which is fine.
Now, feature branch2 shows conflicts instead of saying automatically merge. Was this due to the branch1 merge done previously? If so, is there any way to get an automatic merge option into the master branch without any need to resolve conflicts. As I am sure I have already merged the changes from my master branch into feature branch2.
Related
I have created a branch from another branch. Then I come back to previous branch and work on it. Now I have switched to second branch. But this second branch don't have the new changes of first branch. I just want to update the second branch from first branch without deleting any of them.
But this second branch don't have the new changes of first branch
Switching to the second branch alone is not enough for said branch to reflect changes committed in the first branch.
You would need to git merge branch1 or, if you are the only one working on branch2: git rebase branch1 (if you want to keep a linear history).
Then, and only then, would you see branch1 changes in branch2.
⇒ The OP Waqar Ahmed proposes in the comments:
I have solved this issue but checking out branch2 and pull the branch1
I am a new developer and just starting to ramp up my PR's at work. So I made a PR and before that PR was merged I made another PR. My first PR was finally approved and merged but the second PR doesnt have the changes from the first one. So I am wondering if I merge the second PR without the changes of the first PR will this override my first PR's changes?
That sounds like a bit of a sketchy operation to me. If you're unsure, here's what I suggest.
Suppose your first PR was merged to origin/master and your second PR is on branch pr2. Then I'd do the following:
git checkout master
git pull --rebase origin master
git checkout pr2
git rebase master
Briefly, I'm suggesting you sync your local master branch with upstream, then rebase your pr2 branch on master. This essentially applies the novel commits in master before your novel commits in pr2. At this stage, you'll find out if you get any merge conflicts. If not, you can examine/test your project and decide if merging your PR will be safe.
I'm new to Github and I have a branch that I want to merge with the master. I couldn't merge it via git command line, its very complicated.
I tried to merge it on Github site following below documentation:
Merging a pull request on GitHub
But I got the following message:
There isn’t anything to compare!
Here's the project:
https://github.com/SumayahAlharbi/erecords
What does 4 commits behind master mean?
Update
Please check below pictures:
I thought I did the merging successfully but nothing changes!
What does 4 commits behind master mean?
It means that the master branch has 4 commits which are not present in your branch currently. You need to rebase your branch and then create a New Pull
Request which will be needed to be reviewed and finally approved so
that your branch can be merged with the master.
There isn’t anything to compare!
Check the difference between the master and your branch. Click the Compare icon in Git hub or run this
command from your local branch in Git Bash : git diff --name-only master_branch.
I just checked your repo. The changes of ExportFeature branch are already merged into the master branch, and then the merge is reverted. That's why now if you raise a pull request to merge ExportFeature into master, you would get There isn’t anything to compare!.
See the latest commits on ExportFeature which are already present in the master branch.
The reason you are seeing 4 commits behind master on ExportFeature branch is since the master branch has 4 more commits than the ExportFeature branch. If you see the total commits on ExportFeature branch, it's 7, whereas the total number of commits on the master branch is 11. If you need to do any more changes on the ExportFeature branch, you would need to get the latest changes from the master branch by running the command git pull origin master when your current branch is ExportFeature on your local git terminal.
I've accidentally did some changes directly on my master branch. How do I safely merge my master back in to my release branch without loosing any changes that were done on either the master (which were done by me) and on the release branch, there were changes done by my colleagues in that branch. Please advise.
Switch to Release branch and merge master.
git checkout release-blah-branch
git merge master
If the changes will merge without collisions you are done.
I have master branch of the project. Then I want to add a new feature so I create a new branch called "new_feature", base on master branch. In new_feature branch, everything works fine and I want to delete some files that are no longer useful. But when I switch back to master branch and merge with new_feature branch, these deleted files still exist.
Here is my question: what I have to do to make master branch is exactly the same as the new_feature branch so I can delete new_feature branch.
Thanks in advance!
You need merge new_feature branch to master.
The steps are,
Switch to master branch
Team - Merge, select new_feature branch
Sounds like you forgot to check in the delete. In Eclipse, switch to the feature branch and open the Git Staging view to see changes that are still pending. File deletes get staged automatically, but not committed.
Required sequence is
Delete - commit - push - checkout other branch - merge - commit - push
#Duc Le: You must merge your new_feature branch to your master branch to get all modified file in new_feature branch into master branch.
Maybe something like this you can follow :
Check your branch :
$ git branch
new_feature * (your active branch)
master
Switch to your master branch :
$ git checkout master
Merge your new_feature to master branch without fast-forward mode:
$ git merge --no-ff new_feature
Explanation about merging without fast-forward