GitHub Actions Tutorial Part-3: Code Push

In this section, we will see how to push code with GitHub actions.

We will create a file named example.txt and add some content in it and push it to a new branch that you provide in the workflow.


      - master

name: Create and push file
    name: Create and push file
    runs-on: ubuntu-latest
    - uses: actions/checkout@master
    - name: Create and push file
      uses: './'
        USER_NAME: example
        USER_EMAIL: example@nouser.(none)
        BRANCH_NAME: code-push-example
        COMMIT_MESSAGE: "Action add file"

Here USER_NAME and USER_EMAIL will be the actor who will push the code in the new branch.



# Install git
# Ubuntu container by default do not have git installed.
apt update && apt install git -y

# Add git config
git config --global "$USER_NAME"
git config --global "$USER_EMAIL"


# Create example.txt  
touch "example.txt"

# Put some content in example.txt
echo "You are doing awesome !" > example.txt

# Checkout branch name based on Variable provided in workflow
git checkout -b $BRANCH_NAME

# Stage files and changes
git add .

# Commit message
git commit -m "$COMMIT_MESSAGE"

# Push the code
git push origin $BRANCH_NAME

Push the code and when the action completes you will see the results.

File created with GitHub action
Open file created by GitHub action

You can save more time in the action by creating a custom Docker Image for the action. By applying this you will reduce a step where docker image will be built by action. Don’t worry if you did not understand this, you will learn this by creating more and more time-consuming processes.

If you want to know more about GitHub actions and other GitHub tools checkout GitHub lab at

Leave a comment

Your email address will not be published. Required fields are marked *