Setup
- Install Git.
# windows
winget install Git.Git
# arch
paru -S git
# ubuntu
apt install git
# mac
brew install git
- Set basic configuration.
# full name is fine
git config --global user.name "Your Name"
# use no-reply github email or another aliased email
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
-
use
--localflag inside a repo to override as needed. -
ideally use an aliased email for public repositories.
# my email
git config --global user.email "16041161+j6y@users.noreply.github.com"
Gitea Setup
- Add following to
~/.ssh/config
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 |