1

Is there short-hand version for:

    git checkout master
    git merge feature_branch_xyz

I imagine usage would be something like:

    git merge-to-target <target_branch> <source_branch>


I'm almost certain there is no out-of-the-box way for this. (I've checked manual)

But before creating custom alias (git config --global alias.merge-to-target '!f765() { git checkout $1; git merge $2; } ; f765') I would like to be sure I'm not reinventing stuff.

(just in case I misread the manual, or some other command handles such thing...)

industryworker3595112
  • 3,419
  • 2
  • 14
  • 18

1 Answers1

2

There is no native way to combine checkout and merge.

One alternative is to take advantage of having multiple worktree already checked out (see "Multiple working directories with Git?"), and do a one-command:

git -C /path/to/second/worktree merge source_branch

/path/to/second/worktree would be the path of a worktree where <target_branch> is already checked out.
In that case, you would need only one command.

Note: to create such a second working tree, you go to your current clone and do (again with git 2.5+, preferable 2.8+) with the git worktree command:

cd /path/to/local/repo
git worktree add ../target <target_branch>
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250