Skip to main content
mention bash strict mode
Source Link
chicks
  • 2.9k
  • 3
  • 18
  • 30

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

There is also bash strict mode which builds on set -e with some other things to make coding in the shell less surprising.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

There is also bash strict mode which builds on set -e with some other things to make coding in the shell less surprising.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -eset -e to get bash to exit on any command having an error.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.

Source Link
chicks
  • 2.9k
  • 3
  • 18
  • 30

use variables

Pulling common elements into variables will make those things easier to follow and change later.

BRANCH_TEST="test"
BRANCH_PASSED="test-passed"

git status
git reset --hard
git pull origin $BRANCH_TEST
git checkout origin/$BRANCH_TEST
git pull origin $BRANCH_PASSED
git checkout origin/$BRANCH_PASSED
git merge origin/$BRANCH_TEST
git push origin HEAD:$BRANCH_PASSED

error checking

Is there any chance one of the steps will fail? You could check the return value of each step or just set -e to get bash to exit on any command having an error.

documentation

It would be a good idea to explain what the intent of the code is.

shebang

Presumably this is a bash script. It would be good to make it clear by putting

#!/bin/bash

as the first line.