Reputation: 11071
When I'm on my branch I want to make pull
from the master
to get the latest version of code, then I rebase my branch onto master
and after I push my branch to the server and create a pull request.
Today I do all of this the next way:
my_branch
, I switch to master
branchmaster
, I either execute git pull
or in Intellij use the graphic interface VCS->git->pull
my_branch
and perform the rebasegit push -f
How could I avoid switching from my_branch
to master
and back in Intellij? Is there a way to pull the master
to master
being on another branch?
Upvotes: 4
Views: 5547
Reputation: 555
I created git alias exactly for that. Put it into your ~/.gitconfig
[alias]
update = "!fn() { \
repo=${2:-origin}; \
if [[ $(git rev-parse --abbrev-ref HEAD) = \"$1\" ]]; \
then \
git pull \"${repo}\"; \
else \
git fetch \"${repo}\" \"$1\":\"$1\"; \
fi; \
}; fn"
then you can use git update master
to update your local master without switching to it. Or, if your remote is not origin
but, say, upstream
, you can use git update master upstream
. What about Intellij, seems that there is no such feature out of the box.
Upvotes: 1
Reputation: 1667
Assuming the master branch you talked about is on a remote called upstream, you can run the next 2 commands before pushing your code:
git fetch
git rebase upstream/master
If you didn't set any remotes, the default remote name is origin and in that case the commands are:
git fetch
git rebase origin/master
git fetch won't change any of your local branches, it will just give git information on what exists on the server.
Here is a related StackOverflow question that you might want to also look at when you have time: How to rebase local branch with remote master
Upvotes: 2