1

When I create a new GitHub repository from my GitHub template, the first git commit message is automatically set to this:

Initial commit

How can I override this? I couldn't find a way to change the initial commit message in the settings.

torek
  • 448,244
  • 59
  • 642
  • 775
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
  • I don't think you can. Use the command line to create the first commit, where you have control. – torek Apr 03 '22 at 07:45

2 Answers2

2

It is possible to do this with a GitHub Action that defines the on.create field like this:

# The workflow will run only when `use this template` is used
on:
  create:

See how I managed to do this in my foundry-template project.

Gangula
  • 5,193
  • 4
  • 30
  • 59
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
  • Can you elaborate on your solution? I understand [your code](https://github.com/paulrberg/foundry-template/blob/main/.github/workflows/create.yml) ends up calling `git commit --amend`. However, according to the [GitHub documentation](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#create), the event `create` triggers not (specifically) when a repository is created from a template, but whenever a git reference (branch or tag) is created. How does your workflow not run every time you push a new branch or tag? – djsp Dec 24 '22 at 14:47
  • @djsp It might be true that the workflow runs on every new branch or tag, but in my scenario, I don't mind that, because I am only maintaining a `main` branch, and no tags. However, I don't see why this should be a problem anyway, because of the [check on line 12](https://github.com/paulrberg/foundry-template/blob/main/.github/workflows/create.yml#L12), which ensures that the workflow is never run in the template repo itself. – Paul Razvan Berg Dec 24 '22 at 14:50
2

As mentioned in the comment by @torek, you cannot change the commit message from GitHub Web app directly, you can do it once you clone it in your system using a cli using git rebase -i --root. You can refer to this video for instructions

Below is the steps you need to follow:

  1. Clone the repository locally & Open the folder of the repository in a terminal or your favorite IDE with an integrated terminal
  2. run the following command in the terminal git rebase -i --root
    • This displays all the list of commits in your repository to let you edit (screenshot below).
  3. hit the i key in your keyboard which starts the edit more
  4. Go to your first commit in the list of commits and replace pick with reword
  5. Hit Escape to stop editing
  6. Type :wq on your keyboard (to write and quit) and hit Enter
    • This finally opens up the commit allowing you to change the commit message
  7. Make the change to the commit message and type :wq on your keyboard
    • This makes the changes in you local repository
  8. Thats it, now you can push your changes to your remote repository with git push --force
    • you need to use --force.

Screenshot of git rebase command from terminal

Gangula
  • 5,193
  • 4
  • 30
  • 59