1

I'm playing around with my custom commands, and I'm currently trying to change a remote Git branch programatically using bash.

issue() {
    if [ `git branch --list issue_$1` ]
    then
        git checkout issue_$1
    else
        git checkout -b issue_$1
        git branch -u origin issue_${1}
    fi
}

The idea is this function will try to find the branch issue_X, if it does it switches, otherwise it creates and sets the remote origin.

The problem is git branch -u origin issue_${1} I don't know how to do this, and I'm having trouble googling for it because I don't know what this process is called.

Thanks a lot for the help!

3
  • You are trying to say that you want the else branch to create a new branch, and mark it as tracking an upstream branch of the same name, and you don't know how to do the latter? Just push it. Commented Mar 8, 2018 at 6:14
  • @MauroCasas: I also find the title of your posting confusing. You are talking about a "modified variable", but there is no mentioning of any variable in your posting. Commented Mar 8, 2018 at 8:19
  • @MauroCasas: What problem do you have exactly when setting up the upstream branch? I'm not a git specialist, but the argument to -u should be the upstream branch name. My feeling is that a command git branch -u origin/issue_$1 issue_$1 would be more appropriate. I suggest you remove all tags except git from your posting, as this question doesn't seem to be related to shell scripting, but to the naming of upstream branches. Commented Mar 8, 2018 at 8:30

1 Answer 1

1

I don't know how to do git branch -u origin issue_${1}

If a remote-tracking branch origin/issue_${1} exists you can do git branch -u origin/issue_${1}.

The problem is that in your situation the remote-tracking branch doesn't exit and you have to create it:

git push -u origin issue_${1}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.