git checkout custom_branch && git rebase master
This will update custom_branch with changes from master branch.
Don't forget to make sure master is up to date first. git pull
This is also possible with git checkout custom_branch && git merge master
For an explanation on why the first one is (probably) what you should be using: When do you use git rebase instead of git merge? Answer from tehp on Stack Overflow
git checkout custom_branch && git rebase master
This will update custom_branch with changes from master branch.
Don't forget to make sure master is up to date first. git pull
This is also possible with git checkout custom_branch && git merge master
For an explanation on why the first one is (probably) what you should be using: When do you use git rebase instead of git merge?
git switch custom_branch # switch current working environment to custom_branch
git merge master # merge master branch into custom_branch
This will update your current branch with the changes from your local master branch, the state of which will be that of when you last pulled while on that branch.
I think this is what you are looking for: git merge origin master
Not sure if this is the right place to ask this. My branch is behind origin master by many commits, I tried to git merge master to my branch earlier but my git log history now shows a bunch of other people’s commits, but I actually just wanted to keep my branch up-to-date with master in one commit only, something like “Merge branch ‘master’ into ‘some-branch’” any help is appreciated. Thanks
what does git merge origin/master do? - Stack Overflow
Difference between git merge master and origin/master? - Stack Overflow
git - How to merge remote master to local branch - Stack Overflow
merge - merging (git) origin to my current local working branch - Stack Overflow
git merge origin/master can do one of two things (or error).
In the first case, it creates a new commit that has two parents: the current HEAD, and the commit pointed to by the ref origin/master (unless you're doing something funny, this is likely to be (the local pointer to) the branch named master on a remote named origin, though this is completely conventional).
In the second case, where there is no tree-level merge necessary, rather than creating a new commit, it updates the currently checked-out ref to point to the same commit as is pointed to by origin/master. (This is called a fast-forward merge -- git can be directed to either always or never do this when you merge through command-line flags).
It does not call git commit directly, which is a higher-level (porcelain in the git-parlance) command intended for users.
Calling git merge master/original will try and resolve master/original to a commit, which will almost certainly (again, unless you've done something deliberate) not be the same as origin/master. If you happen to have a remote named master that has a branch named original, it will create a new commit which has that as the second parent.
You may find git help rev-parse to be helpful in deciphering how git attempts to resolve ref names or other notations into commits.
What this does is merges the branch referred to as origin/master into your current branch. The order is very important. The word origin means the place from which you cloned your repository, i.e., the origin of the repository, the word master is just a branch name, however master is usually used as the main branch, or the trunk branch as some other systems call it.
Merge might need to do a commit depending on the state of your development. If your history hasn't diverged from the origin, it can do what is called a fast-forward---all that needs to be done is put the new history on top of yours. If your development has diverged from the origin then if the merge can be done with no conflicts then the merge is done and a new commit is recorded at HEAD to specify the merge and the two parents.
Furthermore, if merging can't be done because of a conflict, your working copy is updated to reflect the fact that there are conflicts, then when you fix them, you manually make the commit that records the merge.
git fetch fetches information on remote branches, but does not make any changes to your local master branch. Because of this, master and origin/master are still diverged. You'd have to merge them by using git pull.
When you make a commit, your local master branch is ahead of origin/master until you push those changes. This case is the opposite, where the origin/master branch is ahead of your local master branch. This is why you are getting different outcomes.
Read https://stackoverflow.com/a/7104747/2961170 for more information.
Using git merge origin/master refers to the master branch on the server. git merge master refers to your local master branch.
By using git pull you can merge them if they diverge.
From your feature branch (e.g configUpdate) run:
git fetch
git rebase origin/master
Or the shorter form:
git pull --rebase
Why this works:
git merge branchnametakes new commits from the branchbranchname, and adds them to the current branch. If necessary, it automatically adds a "Merge" commit on top.git rebase branchnametakes new commits from the branchbranchname, and inserts them "under" your changes. More precisely, it modifies the history of the current branch such that it is based on the tip ofbranchname, with any changes you made on top of that.git pullis basically the same asgit fetch; git merge origin/master.git pull --rebaseis basically the same asgit fetch; git rebase origin/master.
So why would you want to use git pull --rebase rather than git pull? Here's a simple example:
You start working on a new feature.
By the time you're ready to push your changes, several commits have been pushed by other developers.
If you
git pull(which uses merge), your changes will be buried by the new commits, in addition to an automatically-created merge commit.If you
git pull --rebaseinstead, git will fast forward your master to upstream's, then apply your changes on top.
I found out it was:
$ git fetch upstream
$ git merge upstream/master
newbranch should be current branch, to make sure you can checkout it, then you get updated from you repo using fetch and then merge newbranch with master
About checkout: branch, with which you're currently working is already checkout. To switch to another branch you need checkout it. If already you're working with branch you don't need checkout.
git checkout newbranch
git fetch
git merge origin/master
instead merge you can use rebase, in this case last line should be replaced
git rebase origin/master
Merge and rebase just update you branch with information from other branch. Merge get commits from master and add them to your branch. Rebase did the same by a little different way. See Merging vs. Rebasing. For now just forget about rebase, just do merge.
I think you should do:
git stash#store your changes of your local newbranch in a stackgit pull --rebase origin/master#take the origin latest change in local newbranchgit stash pop#pop the changes in step1 that is stored in stackif there is a conflict, you should resolve confict, and then continue to work until you push all of your changes in origin.
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