Git: Commit with a UTC Timestamp and Ignore Local Timezone
When you git commit, Git automatically uses your system’s local timezone by default, so for example if you’re collaborating on a project from Brisbane (UTC +10) and do a commit, your commit will look like this:
If you find it rather unnecessary to include your local timezone in your commits, and would like to commit in UTC time for example, you have two options:
- Changing your computer’s timezone before doing a commit.
-
Using the
--date
commit option to override the author date used in the commit, like this:git commit --date=2014-09-28T01:00:00+0000
The first option is obviously very inconvenient, changing the system’s timezone back and forth between UTC and local for commits is just silly, so let’s forget about that. The second option however, seems to have potential, but manually inputting the current UTC time for each commit is cumbersome. We’re programmers, there’s gotta be a better way…
Bash commands and aliases to the rescue! we can use the date command to output the UTC time to an ISO 8601 format which is accepted by git commit’s date option:
We can then alias it to a convenient git command like utccommit
:
Now whenever we want to commit with a UTC timestamp, we can just:
I'm a seasoned software consultant and technologist based in Brisbane, Australia. I've been helping businesses reach their digital ambitions in the fast-paced tech world for about 15 years.
With expertise in people leadership, software architecture and craftsmanship, the Microsoft ecosystem, web technologies, C#, ASP.NET, and Azure, I team up with organisation leaders to bring their visions to life. My passion lies in making a positive impact through technology.
Outside of my profession, you can catch me diving into self-development, breathwork, fitness, travelling, fishing, camping and making random noises with the flamenco guitar.