porton
porton

Reputation: 5803

Git scripting: ways to do it

I want to script Git. Is just creating a Unix script the best way to do it?

#!/bin/bash

git push origin master &&
git checkout develop &&
git merge master &&
git push origin develop

I was also proposed:

git config alias.pushdev '!git push origin master && git checkout develop && git merge master && git push origin develop'

What are pros and cons of these ways?

Maybe Git alias is better because it would work not with Bash only but also for example with Windows users?

Upvotes: 3

Views: 2123

Answers (2)

Jonathan.Brink
Jonathan.Brink

Reputation: 25383

For functionality you want to share that is more than a few commands I usually prefer scripts.

If you use bash then you should have a high degree of portability as Windows users will very likely be using the "Git Bash" (MINGW32) utility that comes with their download which provides most unix utilities such as grep, sed, awk, etc.

If you name your script something like "git-foo" and have that on your PATH the command will seamlessly integrate with Git.

For example, a script named "git-foo" can be invoked with:

git foo

Another benefit of this approach is you get things like Git's command-line completion for free. So, if you type "git fo" and press enter Git will auto-complete the command for you.

Upvotes: 1

BleuGamer
BleuGamer

Reputation: 307

I prefer Aliases because:

  • Easier to maintain
  • Single commands that work across your system
  • Bash-rc files easily sectioned off

Others prefer shell scrips because:

  • Project specific instructions
  • More control
  • Easy portability

The problem with a shell script, is if you put private repository things in there it can get hairy if it's a public domain, but it's rare for that to be an issue. Generally, git commands are largely user-unique, and other people won't use the same commands that you do, so they fit better as an alias.

Upvotes: 1

Related Questions