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 commit bash script
  • Git Checkout Latest Tag
  • Git completion and PS1 not working: “__git_ps1: command not found” on “sudo -s” or “sudo su” on Ubuntu 12.04
  • How to use a parenthesis character inside a command substitution inside a bash snippet inside a git configuration alias?
  • bash git pre-commit hook running MatLab function does not wait for a result
  • git on Windows: fatal: protocol error: bad line character: @-
  • 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”)

  • Git repository structure and modularity
  • Large Scale Legacy Powerbuilder with GIT or?
  • What is the CouchDB replication protocol? Is it like Git?
  • How can you add commits to a github pull request of another person to your repo if you can't commit to their branch?
  • git-svn and a remote git repo sync
  • Heroku & Django: “OSError: No such file or directory: '/app/{myappname}/static'”
  • 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:

    It links to other sources as well

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