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 Master into a Feature Branch
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 a branch to main branch in Github? - Stack Overflow
git - How to merge master branch into main - Stack Overflow
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
I need advice on how to merge master into a feature branch.
I began working on a new feature last year, and then was pulled away to other things. Master had substantially changed, so I wanted to merge it back into the feature branch, because I can't keep working on the feature until those changes are incorporated into that branch.
I tried this in Github, but I could only merge into master, even when I selected merge into the feature branch. I finally just merged into master and manually updated the changes on the feature branch (which had been overwritten) through cut-and-paste on the feature branch. But this seems like a common task, and I don't want to have to do that again if I can help it.
Thanks in advance for any help; I did consult the Git book, but I couldn't find anything specific about this task.
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.
I hope the master branch contains all of your pushed changes
Steps to merge your branch
- git checkout
main - git merge
master - git push origin
main
Now master is merged in main branch and main branch contains all the changes of master branch.
Or you can go to Pull Request tab and click on the Pull request you have created then scroll down you'll able to see the Merge Pull Request Button.
On clicking that button it will merge your branch into main branch.
In this order using Terminal or Command Prompt,
git checkout main switch to main branch
git pull origin main grab latest updates from main branch
git merge master merge master branch to your main branch
git push origin main push your changes to main
For easier route, you can download Github Desktop app, add your repo into the app and do all the fetch, commit, push and even PULL REQUEST to merge the branch to the main brach.
FYI, naming your other branch master is not recommended and it will making it difficult to distinguish your main (your main branch) and master (other branch). Github has changed its naming from master to main instead to avoid unpleasant term.
I encountered same problem 4 days ago and what I have done is I opened my online repo in git site and went into repo settings and clicked on branches option. I changed the default branch from main to master and i later deleted the main branch as it was empty. tell me if this works for you. 
I had the same issue, I used git pull origin master --allow-unrelated-histories from main branch and then commit + push which solved the problem in my case.
Found the solution in this article
I generally like to merge master into the development first so that if there are any conflicts, I can resolve in the development branch itself and my master remains clean.
(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)
There isn't much of a difference in the two approaches, but I have noticed sometimes that I don't want to merge the branch into master yet, after merging them, or that there is still more work to be done before these can be merged, so I tend to leave master untouched until final stuff.
EDIT: From comments
If you want to keep track of who did the merge and when, you can use --no-ff flag while merging to do so. This is generally useful only when merging development into the master (last step), because you might need to merge master into development (first step) multiple times in your workflow, and creating a commit node for these might not be very useful.
git merge --no-ff development
Personally, my approach is similar to yours, with a few more branches and some squashing of commits when they go back to master.
One of my co-workers doesn't like having to switch branches so much and stays on the development branch with something similar to the following all executed from the development branch.
git fetch origin master
git merge master
git push origin development:master
The first line makes sure he has any upstream commits that have been made to master since the last time updated his local repository.
The second pulls those changes (if any) from master into development
The third pushes the development branch (now fully merged with master) up to origin/master.
I may have his basic workflow a little wrong, but that is the main gist of it.
If you want to merge your branch to master on remote, follow the below steps:
- push your branch say 'br-1' to remote using
git push origin br-1. - switch to master branch on your local repository using
git checkout master. - update local master with remote master using
git pull origin master. - merge br-1 into local master using
git merge br-1. This may give you conflicts which need to be resolved and changes committed before moving further. - Once merge of br-1 to master on local is committed, push local master to remote master using
git push origin master.
To merge branch with master,there are two ways you can proceed
- By Git commands
- By Github Dashboard
Git Commands
Here also you can go with two different commands,first is
- checkout to your master branch using
git checkout master - pull your latest code from the branch you want to merge,use
git pull --rebase origin branch_name. It may give you some conflicts which you can resolve by usinggit status,after resolving you can check if any conflict is more there or not by usinggit rebase --continue.
Second way
- To master you can cherrypick the commits from the branch you want to
merge
git cherry-pick <commit id>.If you are getting conflict usegit cherry-pick --continue.
Actually this is the more suggested way you can proceed.
Merge branch using GitHub Dashboard
This is most easiest way to merge. Create new pull request, select the branch you want to merge and resolve the conflicts.