Git reference sheet #000 Index #001 Introduction #002 Configuration #003 Basics #003-01 Repository #003-02 Staging and committing #003-03 Undoing changes #004 Sign tags #005 Remotes #007 History #008 Archive #001 Introduction Git is a distributed version control system. It tracks changes across any set of files. Core goals: speed, data integrity, and support for distributed non-linear workflows. Each repository holds a complete copy of the project history. #002 Configuration Set global identity used by default in all repositories. ___________________________________________________________ $ git config --global user.email "YOUR_EMAIL" $ git config --global user.name "YOUR_NAME" ___________________________________________________________ Set the default initial branch name. ___________________________________________________________ $ git config --global init.defaultBranch main ___________________________________________________________ Set the default text editor for commit messages. ___________________________________________________________ $ git config --global core.editor vim ___________________________________________________________ Useful shell aliases. ___________________________________________________________ alias glog='git log --stat --decorate' alias gloga='git log --graph --abbrev-commit \ --decorate --date=relative --all' alias garchive='git archive --format=tar.gz HEAD \ -o $(git branch --show-current).tar.gz' ___________________________________________________________ Automatically prune remote-tracking branches. ___________________________________________________________ $ git config --global fetch.prune true ___________________________________________________________ #003 Basics #003-01 Repository Initialize a new repository. ___________________________________________________________ $ git init ___________________________________________________________ Clone an existing remote repository. ___________________________________________________________ $ git clone git://git.example.host/project.git ___________________________________________________________ #003-02 Staging and committing Check status. ___________________________________________________________ $ git status ___________________________________________________________ Stage files. ___________________________________________________________ $ git add path/to/file $ git add . ___________________________________________________________ Commit staged changes. ___________________________________________________________ $ git commit -m "Describe the change" ___________________________________________________________ Unstage a file. ___________________________________________________________ $ git restore --staged path/to/file ___________________________________________________________ Discard working tree changes. ___________________________________________________________ $ git restore path/to/file ___________________________________________________________ Interactive rebase to squash commits. ___________________________________________________________ $ git rebase -i oldest_commit_hash ___________________________________________________________ #003-03 Undoing changes Undo last commit (keep changes staged). ___________________________________________________________ $ git reset --soft HEAD~1 ___________________________________________________________ Restore a file from a previous commit. ___________________________________________________________ $ git checkout COMMIT_HASH^ -- path/to/file ___________________________________________________________ #004 Sign tags Tags are signed with SSH keys through OpenSSH in the OpenBSD base system. Configure git before creating tags. ___________________________________________________________ $ git config --global gpg.format ssh $ git config --global user.signingkey ~/.ssh/id_ed25519.pub ___________________________________________________________ The signing key must be an authorized committer key registered in the verifier allowedSignersFile. ___________________________________________________________ $ git tag -s v-1.0.0 -m "Release 1.0.0" ___________________________________________________________ #005 Remotes Add a remote. ___________________________________________________________ $ git remote add origin git://git.example.host/proj.git ___________________________________________________________ Fetch updates. ___________________________________________________________ $ git fetch --all $ git fetch origin ___________________________________________________________ Prune stale remote branches. ___________________________________________________________ $ git remote prune origin ___________________________________________________________ #007 History Graph log alias. ___________________________________________________________ $ git config --global alias.adog \ "log --all --decorate --oneline --graph" ___________________________________________________________ Show full branch graph. ___________________________________________________________ $ git adog ___________________________________________________________ #008 Archive Create compressed archive. ___________________________________________________________ $ git archive --format=tar \ --prefix=projectname-1.0.0/ main \ | xz > projectname-1.0.0.tar.xz ___________________________________________________________ Using alias. ___________________________________________________________ $ garchive ___________________________________________________________ * * * [1] gopher://sophia.host/0/tools/vim.txt ____________________________________________________________ rev-0.0.1 gopher://sophia.host/0/tools/git-reference.txt