Please do following set of commands in order to merge with the master,
Assuming that you are in branch testBranch and you want to merge the changes with the master,
First checkout to master branch,
git checkout master
Now pull the latest changes in master,
git pull origin master
Merge with the testBranch
git merge testBranch
Push the changes to master
git push origin master
That's it, you are done.
Answer from Actung on Stack OverflowPlease do following set of commands in order to merge with the master,
Assuming that you are in branch testBranch and you want to merge the changes with the master,
First checkout to master branch,
git checkout master
Now pull the latest changes in master,
git pull origin master
Merge with the testBranch
git merge testBranch
Push the changes to master
git push origin master
That's it, you are done.
You could also just create a pull request.
If there are no merge conflicts its easier.
If there are merge conflicts:
git fetch origin
git checkout {branch}
git merge master
Afterwards you have the merge conflict on your branch and you can resolve it.
git add .
git commit -m "{commit message}"
git push
And you have resolved the merge conflict and can merge the pull request onto the master.
Hint: With squash and merge the whole branch is committed as one commit onto master.
How to merge branch to master?
Merge the development branch into master
In the GitHub Desktop client, select the development branch. Make a change to a file, and then commit the changes.
2. Switch to the master branch.
3. Go to Branch > Merge into Current Branch.
4. In the merge window, select the development branch, and then click Merge into master.
Source - https://idratherbewriting.com/learnapidoc/pubapis_github_desktop_client.html
More on reddit.comGit: How to merge branch to master locally and on Github? - Stack Overflow
How do I safely merge a Git branch into master? - Stack Overflow
how to merge branches on GitHub website, besides pull request - Stack Overflow
I have master where i have set some basic code, than i created new branch to test something. Now i want to merge this branch to master (move code from branch to master). I am using GitHub desktop but just can not figure it out how to merge. And i am beginner.
Merge the development branch into master
In the GitHub Desktop client, select the development branch. Make a change to a file, and then commit the changes.
2. Switch to the master branch.
3. Go to Branch > Merge into Current Branch.
4. In the merge window, select the development branch, and then click Merge into master.
Source - https://idratherbewriting.com/learnapidoc/pubapis_github_desktop_client.html
Create a pull request.
How I would do this
git checkout master
git pull origin master
git merge test
git push origin master
If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with what I want to push and also I wouldn't push things at all, that are only for me and my local repository. In your description it seems, that test is only for you? So no reason to publish it.
git always tries to respect yours and others changes, and so will --rebase. I don't think I can explain it appropriately, so have a look at the Git book - Rebasing or git-ready: Intro into rebasing for a little description. It's a quite cool feature
This is a very practical question, but all the answers above are not practical.
Like
git checkout master
git pull origin master
git merge test
git push origin master
This approach has two issues:
It's unsafe, because we don't know if there are any conflicts between test branch and master branch.
It would "squeeze" all test commits into one merge commit on master; that is to say on master branch, we can't see the all change logs of test branch.
So, when we suspect there would some conflicts, we can have following git operations:
git checkout test
git pull
git checkout master
git pull
git merge --no-ff --no-commit test
Test merge before commit, avoid a fast-forward commit by --no-ff,
If conflict is encountered, we can run git status to check details about the conflicts and try to solve
git status
Once we solve the conflicts, or if there is no conflict, we commit and push them
git commit -m 'merge test branch'
git push
But this way will lose the changes history logged in test branch, and it would make master branch to be hard for other developers to understand the history of the project.
So the best method is we have to use rebase instead of merge (suppose, when in this time, we have solved the branch conflicts).
Following is one simple sample, for advanced operations, please refer to http://git-scm.com/book/en/v2/Git-Branching-Rebasing
git checkout master
git pull
git checkout test
git pull
git rebase -i master
git checkout master
git merge test
Yep, when you have uppers done, all the Test branch's commits will be moved onto the head of Master branch. The major benefit of rebasing is that you get a linear and much cleaner project history.
The only thing you need to avoid is: never use rebase on public branch, like master branch.
Never do operations like the following:
git checkout master
git rebase -i test
Details for https://www.atlassian.com/git/tutorials/merging-vs-rebasing/the-golden-rule-of-rebasing
appendix:
- if you are not sure about rebasing operations, please refer to: https://git-scm.com/book/en/v2/Git-Branching-Rebasing