1

I need to do several "two-step" or "three-step" commands in Git quite frequently, that require me to also specify a branch name as a parameter - things like:

git checkout (branch name)
git pull origin (branch name)

or stuff like that. I would like to "automate" this into an alias - but a simple Git alias won't do - right?

So how can I do this in a Bash shell script? I am well versed in MS-DOS/Windows batch scripts - but I am a total newbie to Bash.

All the examples of Bash alias with more than one Git command I've seen so far seem to not have any parameters...... but I am jumping back and forth between various branches, so I definitely need to define which branch to check out and update from the central repo...

Any help? Any blog posts or articles that a *nix newbie would understand? Any pointers are highly welcome!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

2

You can define an alias like this:

[alias]
  chepull = !git checkout $1 && git pull origin

You can do:

git chepull branch_name 

Note: $1 is intentionally not specified in git pull origin, but should work as intended.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Hm.... so if I checkout `SomeExperimentalBranch` - don't I have to define that branch in the `git pull origin`, too, for it to be updated from the central repo ?? – marc_s Apr 12 '12 at 12:22
  • @marc_s - What I mean is, the above alias will do `git pull origin SomeExperimentalBranch` – manojlds Apr 12 '12 at 12:32