Due to my laziness to use git checkout xxx
I want to know is it possible to merge upstream/master
into master
from another branch. My case is like this.
I have `origin` which is my repo.
I have `upstream` which is repo of company.
I have `master` branch.
I have feature/fix branches that are based on `master` branch.
So, basically when I'm in a feature branch I run git fetch upstream
to see is there any update on master
branch, before I push the branch to my origin
(for sending pull request).
If yes then
> git checkout master
> git merge upstream/master
> git push origin master
> git checkout my_feature_branch
> git rebase master
So, I'm looking for an easy way something that takes less time, possibly without switch to master
branch. Is it possible?
Script it maybe?
#!/bin/bash
# git-merge-upstream-to-master-and-rebase
original_branch=$(git symbolic-ref --short HEAD)
git checkout master &&
git merge upstream/master &&
git checkout "$original_branch" &&
git rebase master
You can save it somewhere in your bin path and make it executable. After that, you can start using your single awesome command:
$ git merge-upstream-to-master-and-rebase
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.