Git
Git
FOSS version control system.
Install
- Install Git.
# Windows
winget install Git.Git
# Arch
sudo pacman -S git
# Macos
brew install git
- Set basic configuration.
# full name is fine
git config --global user.name "Your Name"
# best to use no-reply github email or another aliased email
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
-
Setup SSH access.
-
(for gitea) Edit
~/.ssh/config, replace domain appropriately.
Host gitea.nodusk.me
HostName gitea.nodusk.me
User git
Port 222
Usage
Initialize Repo
git init # create new repository
git clone <url> # retrieve remote repository
Stage
git status # show staged files
git add <path> # stage file or folder
git reset <path> # unstage file or folder
git diff # show changes from last commit, filter staged only with --staged
git commit -m "<message>" # commit staged
Branch
git branch #list branches
git branch <branch> # create branch
git branch <branch> origin/<remote-branch> # create brach from specified remote branch
git checkout <branch> # switch branch
git merge <branch> # merge specifed branch wtih current branch
git log # show current branch history
Remote
# origin is a common alias
git remote add <alias> <remote-url> # add remote repository
git remote set-url <alias> <remote-url> # change remote repository
git fetch <alias> # retrive remote updates
git merge <alias>/<branch> # merge current brach with specified remote branch
git pull # fetch and merge current branch with tracking remote branch
git push <alias> <remote-branch> # transmit current branch to specified remote branch
Rewrite
git rebase <branch> # apply commits of current branch ahead of specified branch
git reset --hard <commit> # clear staged, rewrite from specified commit
Commit Messages
| Tag | Description |
|---|---|
| feat | Introduce a new feature to the codebase |
| fix | Fix a bug in the codebase |
| docs | Create/update documentation |
| style | Feature and updates related to styling |
| refactor | Refactor a specific section of the codebase |
| test | Add or update code related to testing |
| chore | Regular code maintenance |