Bash script for defining flags depending on current git branch

Recently I’ve encountered a problem. I have an app that talks to the server. I want it to talk to different servers depending on what branch I’m on right now. I think the way for doing that is create a bash script which creates a .h file like

#define BRANCH @"{here goes branch name}"

The only thing is that I don’t know Bash. At all 🙁

  • Git - How to find all “unpushed” commits for all projects in a directory?
  • Modified terminal prompt to show current Git branch, and now (master) is showing up in all directories
  • How can I put $HOME/opt/git/bin to my PATH?
  • In git, how can I perform a regex replacement on changed lines only?
  • How to use `find -exec sh -c` in a git or shell alias
  • Git Pull from Shell script
  • Here is what I’ve tried

    branch= git branch| grep '*'
    echo $branch
    

    Dunno what to do next… (By the way I’m using Xcode and running this in a “Runs script phase”)

  • Errors with cabal 1.18.1.3 in Windows with latest Haskell Platform (2014.2.0.0)
  • tortoisegit working with branches and merging with origin
  • Openshift redhat for Windows: rhc command error
  • Teamcity to github List remote refs failed not authorized jgit
  • Git - Save unfinished merge changes and checkout another branch
  • Is there an easy way to manage multiple versions of git?
  • 3 Solutions collect form web for “Bash script for defining flags depending on current git branch”

    This creates the file for the current branch:

    current_branch=$(git branch --no-color | grep '*' | sed 's/^\*.//')
    echo "#define BRANCH @\"$current_branch\"" > file.h
    

    file.h would contain: #define BRANCH @"your current branch"

    You can get the current Git branch with:

    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
    

    Use vcprompt

    It supports Git, Mercurial, subversion and others(?)

    Here is one repo: https://github.com/xvzf/vcprompt#readme

    It links to other sources as well

    Git Baby is a git and github fan, let's start git clone.