This workflow installs and configures GNU/Git, the decentralized
version control system.
Source Control
Introduction
This workflow installs and configures git
version control
system. It also provides git-fs
, shortcut shell scripts, and Emacs
integration via magit
.
Install
Git can be installed from the official GNU/Guix repository.
(specifications->manifest (list "git-lfs" "git" ))
Usage
To run this configuration run,
litdoc --verbose sc
Shell Integration
Shortcuts for quickly collecting git repository information.
Show full path to the root of the current
git
repository(if any).
gr(){
git rev-parse --show-toplevel $@
return $?
}
Shortcut to git status
gg(){
git status
}
Show git log
of the current repository.
gl(){
git log $@
}
Undo last git commit
gu() {
git reset --soft HEAD~1
}
Undo the last N git commits,
gun(){
git reset --soft HEAD~${1:-1}
}
Sign-off the last git commit of the current repository
singnoff(){
git --amend --sign-off $@
}
Emacs Integration
Magit is the de-facto standard for integrating git with Emacs
(use-package magit
:guix (:name emacs-magit)
:config
(message "magit config ready!")
:commands
(magit-blame-mode
magit-commit
magit-log
magit-status)
:general
<<magit-kb>> )
Emacs Key Bindings
(kb::def :states 'normal
"g" '(:ignore t :which-key "git")
"gs" '(magit-status :which-key "status")
"gl" '(magit-log :which-keu "log"))
Application Notes
Git Workflow
The key to using git is crafting a good commit. A good commit should do one thing concisely and has to leave the repository in a working state. That's about it.
Commit Messages: the subject-line should describe what changed and why the change was introduced in 50 chars or less. And prefer imperative forms when possible.
if commit is applied, then [insert commit subject-line] – This should make real good sense
Git Workflow? All things being equal, choose the simplest workflow. The forking workflow is one example See Forking workflow .
SSH Access: enable SSH protocol with git remote set-url
command:
git remote set-url origin [git@coffee.hub.com:user/path.git]
If you have not already setup an SSH key, one can be generated
using the ssh-keygen
command.
mkdir -p ~/some/personal/directory
pushd ~/some/personal/directory
#create two SSH keys for the sake of demonestration
ssh-keygen -t ed25519 -C "me@workforcofee" -f "${HOME}/.ssh/coffee"
# => ~/.ssh/coffee.pub, public key
# => ~/.ssh/coffee, private key
ssh-keygen -t ed25519 -C "me@workforbeans" -f "${HOME}/.ssh/beans"
# => ~/.ssh/beans.pub, public key
# => ~/.ssh/beans, private key
# Register the keys on this machine
ssh-add coffee
ssh-add beans
Add the generated keys to ~/.ssh/config
Notice, to unregister a given key-file you can run
ssh-add -D ~/.ssh/coffee
Host coffee.hub
HostName coffee.hub.com
User git
IdentityFile ~/.ssh/coffee
Host git.beans
HostName git.beans
User git
IdentityFile ~/.ssh/beans
Signing Commits
Git supports signing and verifying work, commits and tags, using GPGsn:]].
Select GPG Key: For the sake of simplicity assume there is one or more GPG key availablesn:]].To select from a list of available keys run,
gpg --list-keys --keyid-format long pub <PRIMARY-KEY-INFO>/<KEY_ID> <CREATE-DATETIME> [SC] [expires: <EXP-DATETIME] <FINGERPRINT> uid <USER-INFO> <EMAIL> sub <SUB-KEY-INFO>/<SUBKEY-ID> <CREATE-DATETIME> [E] [expires: <EX-DATETIME>]
Take a note of <KEY-ID>
and make sure the key is
tagged with [S]
which stands for signing. For example
if the key is marked with [E]
, that means it can only
be used with encryption.
Configuring git
: add the selected <KEY-ID> to git
configuration(.git/config
).
git config user.signingkey <KEY-ID>
git config gpgSign true
Add GPG Key to Gitlab: add the public GPG key to Gitlab to enable commit verification following their guide. The public key can be generated using,
gpg --armor --export > gpg.public.txt
Signing Commits: once configured git
commits and tags can be signed off using the
--sign-off
or its short form -S
option,
git commit -S -m "commit description"
Also, git log --show-signatuers
can be used to verify commits were
signed off properly.