written by Eric J. Ma on 2023-08-26 | tags: til github github actions github workflow git configuration workflow runner github permissions repo settings workflow permissions github token
Today, I learned how about a hidden setting that's needed to enable GitHub Actions to push code to its associated repo, and wrote it out as a tutorial. As a bonus, I also share how to correctly configure git within a GitHub actions workflow. Discover the trick with me!
Today I learned how to ensure that GitHub actions is capable of pushing code to its associated repo.
The tl;dr is:
It'll look something like this:

Underneath the hood, there is a default secrets.GITHUB_TOKEN that is granted to a GitHub Actions' Workflow runner. The default permissions are read-only, as it needs to be able to clone the repo. However, we can enable it to push by enabling write permissions.
Once we've configured that setting, within a GitHub actions workflow, we need to ensure that git is configured correctly before pushing. In one of my workflow configuration files, I have it split up into two steps:
- name: Configure Git run: | git config user.name github-actions git config user.email github-actions@github.com ... (other stuff goes here) - name: Push changes with tags run: | git push && git push --tags
@article{
ericmjl-2023-enable-github-actions-to-push-code-changes,
author = {Eric J. Ma},
title = {Enable GitHub Actions to Push Code Changes},
year = {2023},
month = {08},
day = {26},
howpublished = {\url{https://ericmjl.github.io}},
journal = {Eric J. Ma's Blog},
url = {https://ericmjl.github.io/blog/2023/8/26/enable-github-actions-to-push-code-changes},
}
I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.
# TODO(eric): learn how to learn anything. feb 2027.
If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!