By Qin Yu, last updated in Feb 2024. I hope this will save time for everyone.
- First-Time Git Setup
- Connect to GitHub with SSH
- How to really commit in the past with Git for GitHub
- Reference
Scope | File |
---|---|
system level | /etc/gitconfig |
user level | ~/.gitconfig or ~/.config/git/config |
repository level | .git/config |
Each level overrides values in the level above. You can all of your settings and where they are coming from using:
$ git config --list --show-origin
This should print nothing if git
has not been used.
-
Set identity
$ 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, you can run the command without the
--global
option when you’re in that project. -
Set editor Now set
emacs
as the default editor:$ git config --global core.editor emacs
If not configured, Git uses your system’s default editor.
-
Set colour Also, enable coloured output in terminals:
$ git config --global color.ui true
-
Check keys to reuse
$ ls -alhF ~/.ssh/
if no files like
~/.ssh/id_rsa
and~/.ssh/id_rsa.pub
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
-
Paste public key to GitHub i.e. copy the content of
~/.ssh/id_rsa.pub
into GitHub -> Personal Settings -> SSH and GPG keys -> New SSH Key -
Test
$ ssh -T git@github.com
The three keys are argument --date
, and two environment variables GIT_AUTHOR_DATE
& 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"
Note that the last timestamp of modification can be printed by ls -lv --time-style="+%Y-%m-%dT%H:%M:%S"
, I recommend you alias ll
as my favourite:
$ ls -ahlv --color=auto --group-directories-first --time-style="+%Y-%m-%dT%H:%M:%S"
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
...
Thanks for this, very useful - worked first time for me!