Home > front end >  Git alias for checkout branch, pull and checkout back
Git alias for checkout branch, pull and checkout back

Time:05-14

We are using the Feature-Branch-Workflow, which means others merge theire changes to the dev-branch that I want to merge into my feature branch. As it happens a lot I would like to have a simple git alias which does:

  1. Checkout the dev branch
  2. Pull
  3. Checkout the previous branch

I want to do the merge myself, as sometimes changes block the checkout or pulls can fail.

My current state is:

[alias]
  pull-and-back = !git checkout $1 && git pull && git checkout @{-1}

which sadly gives the error error: pathspec 'dev' did not match any file(s) known to git.

What is going wrong? I assume as the exclamation mark causes the command to be interpreted as bash code the last part @{-1} is not evaluated by git but by bash instead.

CodePudding user response:

You'd have to use an ad hoc bash function to pass your parameter :

git config alias.pab '!f() { git checkout $1 && git pull && git checkout -; }; f'

As a note, git checkout - is a handy shortcut for git checkout @{-1}, but both work.

  • Related