Step 1: Create a personal access token on GitHub.
Step 2: Create a new branch in GitHub using REST API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
## Declare some Variables GITHUB_PAT_TOKEN=' GITHUB_REPO_NAME=' GITHUB_USER_NAME=' GITHUB_BRCH_NAME=' ## Get the last commit SHA in a Variable COMMIT_SHA=$(curl \ --request GET \ --silent \ --header "Authorization: token $GITHUB_PAT_TOKEN" \ https://api.github.com/repos/$GITHUB_USER_NAME/$GITHUB_REPO_NAME/commits | jq -r .[1].sha) ## Create a new branch in GitHub curl \ --request POST \ --silent \ --header "Authorization: token $GITHUB_PAT_TOKEN" \ --data '{ "ref": "'"refs/heads/$GITHUB_BRCH_NAME"'", "sha": "'"$COMMIT_SHA"'" }' \ https://api.github.com/repos/$GITHUB_USER_NAME/$GITHUB_REPO_NAME/git/refs |