Git
- Free git book: https://git-scm.com/book/en/v2/
- π git out of town
- Commit Often, Perfect Later, Publish OnceβGit Best Practices
- Oh Shit, Git!?!
Repos
Initialise a git repo
Make a .gitignore file. In terminal:
Make directory into git repo and connect to remote:
Now you have two options: Push everything to remote repo:
Pull everything from remote repo:
Pull from another repo
Pulling another branch and then merging it
Delete a git repo
- Option 1:
CMD
+SHIFT
+.
to show hidden files - Option 2:
rm -fr .git
in the folder that has the repo
Rename a repo
- Go to the remote host (for example, https://github.com/User/project).
- Follow the hostβs instructions to rename the project (will differ from host to host, but usually Settings is a good starting point).
- Go to your local repository directory (i.e., open a command prompt and change to the repositoryβs directory).
- Determine the new URL (for example,
[email protected]:User/project-new.git
) - Set the new URL using Git:
Branches
Rename branches: How to Rename a Local and Remote Git Branch β A Quick Guide
Manually approve each change in a merge
Merge and delete a branch
Local
Remote
Commits
Conventional commits
- Conventional Commits
- Cheat Sheet: https://kapeli.com/cheat_sheets/Conventional_Commits.docset/Contents/Resources/Documents/index
Using emoji in commits
Source: https://opensource.com/article/19/2/emoji-log-git-commit-messages
- Imperative
- Make your Git commit messages imperative.
- Write commit message like youβre giving an order.
- e.g., Use β Add instead of β Added
- e.g., Use β Create instead of β Creating
- Rules
- A small number of categories are easy to memorize.
- Nothing more, nothing less
- e.g. π¦ NEW, π IMPROVE, π FIX, π DOC, π RELEASE, and β TEST
- Actions
- Make Git commits based on actions you take.
- Use a good editor like VSCode to commit the right files with commit messages.
- β¨ NEW: IMPERATIVE_MESSAGE
- Use when you add something entirely new.
- e.g., β¨ NEW: Add Git ignore file 2.π IMPROVE: IMPERATIVE_MESSAGE
- Use when you improve/enhance piece of code like refactoring etc.
- e.g., π IMPROVE: Remote IP API Function
- π FIX: IMPERATIVE_MESSAGE
- Use when you fix a bug. Need I say more?
- e.g., π FIX: Case converter
- π DOC: IMPERATIVE_MESSAGE
- Use when you add documentation, like README.md or even inline docs.
- e.g., π DOC: API Interface Tutorial
- π RELEASE: IMPERATIVE_MESSAGE
- Use when you release a new version.
- e.g., π RELEASE: Version 2.0.0
- β TEST: IMPERATIVE_MESSAGE
- Use when you release a new version.
- e.g., β TEST: Mock User Login/Logout
Misc
Remove a file
Clean up loose object
error
Submodules
Ignore all subdirectories
Print a changelog
Generating release notes from git commit messages using basic shell commands (git/grep) | SAP Blogs
Since last release
My categories
β¨ New
π Improvements
π Bugs
π Docs
My aliases
release [VERSION NO]
: Release a new Obsidian version
Workflow
Inspired by A successful Git branching model Β» nvie.com
Main branches (infinite lifetime)
main
: code is always production-readydev
: always reflects the latest working changes
dev
merges into main
when code is stable. Therefore each dev
into main
merge is a new release by definition
Supporting branches (limited lifetime)
Feature/topic branches
- may branch off from:
dev
- must merge back into:
dev
- naming convention:
iss2
Merge withgit merge --no-ff myfeature
to not loose history
Release branches
- may branch off from:
dev
- must merge back into:
dev
andmain
- naming convention:
release-*
Branch of from dev
when it is almost ready for another release.
Hotfix branches
- may branch off from:
main
- must merge back into:
dev
andmain
- naming convention:
hotfix-*
They are like release branches but unplanned.
Resetting local changes
git reset --hard HEAD
reset back to HEAD of the branchgit clean -df
Discard any new files or directories