Skip to content

Instantly share code, notes, and snippets.

@DrPsychick
Last active August 4, 2022 07:46
Show Gist options
  • Save DrPsychick/9828a58df91117aedce0df2b3bc2fba8 to your computer and use it in GitHub Desktop.
Save DrPsychick/9828a58df91117aedce0df2b3bc2fba8 to your computer and use it in GitHub Desktop.
git commands for automation

create or update a version branch from master

  • only do this if your branch is just based on a different version than master
  • it is discouraged to do this for branches that have significant differences to master!
  • see it in action: https://github.com/DrPsychick/docker-telegraf
# make sure to have your origin set correctly
# git remote set-url origin "git@github.com:DrPsychick/docker-telegraf.git"

branch="testbranch"
# checkout master from origin, skip if you already have a fresh checkout!
git checkout --track origin/master

# create new local branch (push later) and pull from origin
git checkout -b $branch
git pull origin $branch # fails if branch is not (yet) on origin, but does not matter

# does not always work:
#create=$([ -z "$(git branch -r |grep "$branch")" ] && echo "-b " || echo "--track origin/")
#git checkout $create$branch

# merge master and resolve conflicts by ignoring the branch version and commit
git merge -X theirs --no-edit --commit master

# do and commit changes, keep it simple
#sed -i -e 's/OLDVERSION/NEWVERSION/' file
#run tests/build/...
#git add file && git commit -m 'automated commit'

# push to origin and update/track the remote
git push -u origin $branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment