By Qin Yu, last updated in March 2026. I hope this helped both human and AI.
- First-Time Git Setup
- Connect to GitHub with SSH
- How to really commit in the past with Git for GitHub
- How to reflect the actual authorship
- References
Git uses three configuration levels, each overriding the previous one:
| Scope | File |
|---|---|
| system level | /etc/gitconfig |
| user level | ~/.gitconfig or ~/.config/git/config |
| repository level | [repository]/.git/config |
To view all active settings and where they are coming from:
git config --list --show-originThis should print nothing if git has not been used.
-
Set Git name and email
git config --global user.name "John Doe" git config --global user.email "johndoe@example.com"
If you want to override this with a different name or email address for specific projects, run the command without the
--globaloption when you’re in that project directory. -
Set Git editor Now set
emacsas the default editor:git config --global core.editor emacs
If not configured, Git defaults to your system editor.
-
Set colour Also, enable coloured output in terminals:
git config --global color.ui true
-
Check keys to reuse
List existing SSH keys:
ls -alhF ~/.ssh/If no files like
~/.ssh/id_rsaand~/.ssh/id_rsa.pubare found, then: -
Generate key pair
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -
Add key to ssh-agent
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
If you are using a Mac, use
ssh-add --apple-use-keychain ~/.ssh/id_rsa. -
Paste public key to GitHub
i.e. copy the content of
~/.ssh/id_rsa.pubinto GitHub -> Personal Settings -> SSH and GPG keys -> New SSH Key -
Test connection
ssh -T git@github.com
The three keys are the argument --date and two environment variables: GIT_AUTHOR_DATE and GIT_COMMITTER_DATE.
GIT_AUTHOR_DATE="2024-01-01T00:00:00" GIT_COMMITTER_DATE="2024-01-01T00:00:00" git commit --date="2024-01-01T00:00:00"You can view the last modification timestamp using:
ls -lv --time-style="+%Y-%m-%dT%H:%M:%S"I recommend my favourite alias for ll:
$ alias ll='ls -ahlv --color=auto --group-directories-first --time-style="+%Y-%m-%dT%H:%M:%S"'
$ ll
total 4220
...
drwxr-sr-x 8 qyu hpc-088 4096 2024-02-01T18:51:03 datasets
drwx------ 6 qyu hpc-088 4096 2024-02-05T20:24:59 downloads
drwxr-sr-x 2 qyu hpc-088 4096 2022-05-03T22:31:54 environments
...To avoid pasting three times, I added another alias to ~/.bashrc:
alias gitpast='f(){ GIT_AUTHOR_DATE="$1" GIT_COMMITTER_DATE="$1" git commit --date="$1"; }; f'Then, I can commit in the past with a single command:
gitpast "2024-01-01T00:00:00"I believe that whoever discovered a bug or proposed the fix should be credited as the author of the commit, even if they were not the person who actually made the commit. To reflect the actual authorship:
$ git commit -m "fix(ci): example
>
> Co-authored-by: GITHUB-USER <HELPFUL_DUDE@EXAMPLE.COM>
> Co-authored-by: ANOTHER-HELPFUL-PERSON <ANOTHER-HELPFUL-PERSON@EXAMPLE.COM>"
Thanks for this, very useful - worked first time for me!