A collection of commands for me to get things done.
Setup
Cloning Repository
Setting up Origin
Commit
Commit Amend
Commit Reset File
Branches
Create Branch
Switching Branch
Reset Branch
Fast Forwarding A Branch
Delete A Branch
Handling the copy mistakes in git
TLDR; you can’t its git that decides, however you can configure a threshold.
Aliases
# create alias
git config --global alias.tree "log --graph --all --format='%C(yellow)%h%C(reset) %C(cyan)%as%C(reset) %C(bold)%s%C(reset) %C(dim)%an%C(reset)%C(auto)%d%C(reset)'"
# use with
git tree# create alias
git config --global alias.lg "log --oneline --graph --decorate --all"
#use with
git lgCross-Branch & History Tricks
Restore a file or folder from another branch into your current working tree (stays on current branch, no merge/commit — just drops the files as unstaged changes):
git checkout <branch> -- <path>Same but targeting a specific commit hash instead of a branch:
git checkout <commit-hash> -- <path>View what a file looked like on another branch without touching your working tree:
git show <branch>:<path/to/file>Find any commit that added or removed a specific string across all history:
git log -S "some string" --allStash only specific files instead of everything:
git stash push <path>Binary search through history to find which commit introduced a bug:
git bisect start
git bisect bad # current commit is broken
git bisect good <commit-hash> # known good commit
# git checks out midpoints; mark each good/bad until it pinpoints the culprit
git bisect reset # when doneWorktrees & Bare Clones
A normal clone ties you to one checked-out branch at a time. Worktrees and bare clones let you have multiple branches checked out simultaneously in separate directories — no stashing, no switching.
Bare Clone
A bare clone stores only git internals with no working tree. Used as a base for worktrees:
git clone --bare <repo-url> <folder-name>Convention is to name the folder with a .git suffix:
git clone --bare git@github.com:user/repo.git repo.gitWorktrees
Add a worktree — checks out a branch into a new directory alongside your bare clone:
git worktree add <path> <branch>Example — working on main and a feature branch simultaneously:
cd repo.git
git worktree add ../repo-main main
git worktree add ../repo-feature feature/my-featureEach directory is a fully functional working tree sharing the same git history. Changes in one are immediately visible to the others via git (commit, merge, rebase, etc.) without any pushing.
List active worktrees:
git worktree listRemove a worktree when done:
git worktree remove <path>Why This Matters
The typical use case is avoiding the git stash / git switch cycle when you need to context-switch mid-work. Each worktree has its own index and HEAD so you can have a long-running build in one terminal while actively editing another branch in a second terminal.
Git Software - GUI
Official Git software
https://git-scm.com/
GUI’s can be found here
https://git-scm.com/tools/guis
Personally I’ve used GitKraken since it’s been free and gone through different product phases. It’s by far one of the best GUI’s I’ve used making complex tasks of branch management,
https://www.gitkraken.com/git-client
Their choice to make access to private repositories (for example self owned on GitHub) require payment is the reason I have stopped using it. Primarily I use CLI and VS Code’s interface. (Damn I miss rebasing with GitKraken)