Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Git alias for checkout branch, pull and checkout back

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading