48

I know that Git commits should be made for each logical change, but what is the convention (if any exist) for the first commit?

[note: I'm not inviting opinion/discussion on this - if there isn't a common convention then fine].

For instance I've started a website from scratch with index.html - my first 'logical change' commit could be anything from adding the <head> elements, adding the HTML structure, or adding the basic content and CSS. Or should the first commit be the first 'working' version?

Edit: I don't mean the commit message; I mean the content of the files.

andydavies
  • 3,081
  • 4
  • 29
  • 35
  • 9
    My convention is `git commit --allow-empty`, so I have an empty starting point, allowing me to create entirely new branches unrelated to anything in the repo, which can come in handy. – Kenney Jan 30 '16 at 15:31
  • 1
    Just because you're not inviting discussion/ opinion doesn't mean you're not going to get it :) I like to go with "Abandon all hope, ye who enter here" (the inscription at the entrance to Hell in Dante's inferno). If that's too literary, "first post!" works too. Seriously, though, what does it matter? Are there any consequences if an unconventional message is used? Well, apart from a message like, "Initial commit, and by the way the root password to the production server is asdf123". Don't be afraid of commitment...write a message and get back to your code. – Paul Jan 30 '16 at 16:21
  • 1
    I don't mean the commit message - I mean what should the content of the committed files should be (I've edited the question to clarify) – andydavies Jan 30 '16 at 16:30
  • 1
    @Kenney So do I. An inital empty commit also gives the benefit of being able to rebase or filter-branch the whole repo without the need of extra (and ugly) switches like `--root`. – PerlDuck Jan 31 '16 at 15:05

4 Answers4

49

Usually the first commit is named "Initial commit".

As best practice its include a README file describing the project.
The README is usually is a md file.

Just for fun read this: Funny initial git commit messages:

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • You can put any code you wish as well. but since this is the first commit you might not have enough content yet so README is a decent content for the first commit. – CodeWizard Jan 30 '16 at 15:56
16

It seems there is no established convention then (for the content; not the message).

I found this article about best practice useful: https://sethrobertson.github.io/GitBestPractices/

andydavies
  • 3,081
  • 4
  • 29
  • 35
  • No mention in the article about "root" or "initial commit". I dealt with this before [1], but to summarize the convention once more after years: - Tag the commits you care about, for example 'root', 'root-commit', number them. Whatever. - Use `git describe` to see where you are, no tags means describe gives an error. [1] https://stackoverflow.com/a/12503512/325566 – mpe Nov 20 '18 at 14:12
13

As others have reported, I haven't found a standard convention, so next I will share what I usually do.

After creating the repo, I create an empty commit which message is Initial empty commit. You have to pass the option --allow-empty. Otherwise, you will get a message saying nothing to commit.

$ git init # creates repository
$ git commit --allow-empty -m'Initial empty commit' # creates empty commit

I like to do it this way because it makes me think of this commit as the empty root of my repository. Besides, I can immediately push this repository without any content. After this commit I usually add the README.md.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
1

I'm not sure if there's any particular convention for a first commit. I always try to have at least some resemblance of a project skeleton, and likely a README file describing intended purposes.

DominicEU
  • 3,585
  • 2
  • 21
  • 32