Question

I've spent a fair amount of time over the past few days on SO reading through threads but still haven't found a decent answer for this.

If I'm working in a feature branch and after a few days I want to pull in the latest changes from master I run the command:

git stash; and git checkout master; and git pull origin master; and git checkout <FEATURE BRANCH>; and git merge master; and git stash apply;

If that looks a little off it's because I use Fish and not Bash. Just replace all the ; and with && to get it to work in Bash.

Anyways, I'd like a git alias called "remaster" that automatically does this for me so that when I type git remaster it fires of all those commands. The biggest challenge is getting the feature branch's name and saving it for use later in the sequence when we re-check it out.

Anyone have any way to do this or any ideas?

Était-ce utile?

La solution

You can use git fetch and merge remote changes to your branch with git merge origin/master.

That alias works in bash, so you probably wanna port it to a fish:

[alias]
    remaster = "!f() { git stash && git fetch origin && git merge origin/master && git stash apply; }; f"

But anyway, current branch name could be retrieved via git rev-parse --abbrev-ref HEAD.

Autres conseils

You can reduce the number of commands by merging with origin/master, like so:

git stash
git fetch origin
git merge origin/master
git stash pop

You can make a macro based on this:

[alias]
remaster = "!f() { git stash && git fetch origin && git merge origin/master && git stash pop }; f"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top