GIT

1. Commit Convention: Conventional Commits (simplified)

Adopt Conventional Commits — it’s the industry standard, dead simple, and directly powers automated changelogs.

Format

<type>(scope): description

That’s it. The scope is optional. Keep descriptions short and in lowercase imperative mood.

Types for your dotFiles repo

Type When to use Example
feat Add a new config, alias, function, or tool feat(zsh): add extract function for archives
fix Fix a broken config or typo that breaks things fix(ssh): correct ControlPath socket location
docs README, comments, CONTRIBUTING updates docs: update quick start instructions
chore Maintenance, dependency bumps, cleanup chore: update chezmoi ignore list
refactor Restructure without changing behavior refactor(git): split aliases into categories
style Formatting, whitespace, cosmetic style(vim): normalize indentation to 2 spaces
ci GitHub Actions, linting config ci: add shellcheck workflow
test Add or update tests test: add zsh syntax validation

Scopes (optional, use when it adds clarity)

zsh, git, ssh, vim, tmux, starship, curl, wget, chezmoi, ghostty

Quick examples

feat(zsh): add alias for docker compose
fix(git): use correct signing key format
docs: add commit convention to CONTRIBUTING.md
chore: bump starship config to v1.x format
refactor(ssh): reorganize config into blocks
ci: add chezmoi template validation

Update my last buggy commit to end up with 1 clean commit instead

Pushing several commits with the same commit message is not a good practice, it make your changelog messy with duplicate entries.

You can squash commits before pushing. This replaces your last commit instead of creating a new one (use with git push –force if already pushed).

git add .
git commit --amend --no-edit
git push --force

Nuke everything except current code

The commit history doesn’t make sense, and disk space is ridiculous for a project with a lot of moving parts. It’s time to start over and enforce commit message that reflect the underlying change in a short, precise manner.

cd git-repository
du -sh .git
cp .git/config .
rm -rf .git
git init
cp config .git
git add .
git commit -m "Initial commit after deleting the history"
git push -u --force origin master // or git push --mirror --force
du -sh .git

Update my last buggy commit to end up with 1 clean commit instead

Fresh start for a #Vigie/GIT repository

Delete git history, remove unused files , and reducing disk size of repository for. How to delete all commit history but keep the code in its current state?

This is the best way to remove unused files that are taking too much disk space

messages reflect the underlying change in a short, precise manner.

Install CLI

GitHub CLI .

  • gh auth login
  • gh repo create test —private
    • gh repo fork , which works like git clone except forking the target repository and making a copy in your account.
  • gh repo list , which prints out a list of your repositories.
  • gh repo rename , changes the name and URL.

Git EMoji CLI

Resetting untracked files

Git reset is good but you also need Git clean bring your local repo to 100% parity with the state of the remote,

cd git-repository
git reset
git clean -d —force

Clean up the git repo and reduce its disk size

cd git-repository
du -sh .git
git remote prune origin && git repack && git prune-packed && git reflog expire —expire=1.month.ago && git gc —aggressive
du -sh .git

Nuke everything except current code

The commit history doesn’t make sense, and disk space is ridiculous for a project with a lot of moving parts. It’s time to start over and enforce commit message that reflect the underlying change in a short, precise manner.

Easy way

cd git-repository
du -sh .git
cp .git/config .
rm -rf .git
git init
cp config .git
git add .
git commit -m "Initial commit after deleting the history"
git push -u --force origin master // or git push --mirror --force
du -sh .git

Safer way

git checkout —orphan newBranch git add -A # Add all files and commit them git commit -m ‘Clear history’ git branch -D master # Deletes the master branch git branch -m master # Rename the current branch to master git push -f origin master # Force push master branch to github git gc —aggressive —prune=all # remove the old files

github - Make the current commit the only (initial) commit in a Git repository? - Stack Overflow

Giving up and cloning the remote repository

Let’s get back to the state of the remote repository, This will clone the master main branch by default, use git clone -b branch-name for something specific.

sudo rm -r git-repository
git clone https://github.com/bhdicaire/git-repository.git
cd git-repository

Source: Git – CloudSavvy IT #gitflow stories | HackerNoon #github stories | HackerNoon #git stories | HackerNoon How (and why!) to keep your Git commit history clean|GitLab Archive - Git Better

Git tagging - A brief guide - by Srebalaji Thirumalai

Learn More Than the Basics

You can surely “survive” by knowing just a handful of Git commands. But you’ll be missing out on so much of Git’s power if you don’t learn about the advanced features! To make only three examples:

  • The Reflog can help you find seemingly lost commits. This can be tremendously helpful when you just “deleted” some commits that you shouldn’t have!

  • Interactive Rebase can help you clean up your commit history before you share it with your team. This makes for a much cleaner and easier-to-understand codebase in the long run!

  • Undoing mistakes is a core skill for every software developer. Git allows you to undo almost anything , but you have to learn the tools and commands to do this.