What is the difference between push branch and merge to master then push?

git

Solution

This:

git checkout myBranch
git push origin myBranch:master

just attempts to do a fast-forward (i.e. non-forced update) push of `myBranch` to `master`. If `master` is reachable from `myBranch`, i.e. `master` doesn't contain any commits that `myBranch` doesn't also have, then the push will succeed; otherwise, the push will be rejected.

The preceding `git checkout myBranch` is irrelevant to the `git push`, since you're using the refspec `myBranch:master`. You can learn more about refspecs at Git Internals - The Refspec.

This:

git checkout master
git merge myBranch
git push

actually merges `myBranch` into `master`, and then attempts to push it to a remote (with a default configuration of a Git repo, the remote will be origin).

Because `myBranch` is actually merged into `master`, then assuming the remote `master` is behind the local one, i.e. it doesn't contain commits that the local one doesn't also have, then the push will succeed, otherwise it will fail.

Problem

One way: ``` git checkout myBranch git push origin myBranch:master ``` Another way: ``` git checkout master git merge myBranch git push ``` What is difference between these two?

Original source