computing:git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| computing:git [2026/04/26 18:22] – [Move Between Branches] oscar | computing:git [2026/10/01 10:42] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== GIT ====== | ||
| - | ---- | ||
| - | ==== Getting Started ==== | ||
| - | ^Task^Command^ | ||
| - | |Start a new repo|git init| | ||
| - | |Clone an existing repo|git clone < | ||
| - | ==== Configure Git ==== | ||
| - | ^Task^Command^ | ||
| - | |Set a config option |git config user.name 'Your Name'| | ||
| - | |Set a config option |git config user.email 'Your email' | ||
| - | |Set option system wide in / | ||
| - | |Set option globally in ~/ | ||
| - | |Set option locally in the repository .git/config file |git config --local ... | | ||
| - | |Add an alias|git config alias.st status| | ||
| - | |See all possible config options| man git-config| | ||
| - | |||
| - | ==== Prepare to Commit ==== | ||
| - | ^Task^Command^ | ||
| - | |Add untracked file or unstaged changes|git add < | ||
| - | |Add all untracked files and unstaged changes|git add .| | ||
| - | |Choose which parts of a file to stage |git add -p| | ||
| - | |Move file|git mv <old> < | ||
| - | |Delete file|git rm < | ||
| - | |Tell Git to forget about a file without deleting it|git rm --cached < | ||
| - | |Unstage one file|git reset < | ||
| - | |Unstage everything|git reset| | ||
| - | |Check what you added|git status| | ||
| - | |Check what you added, short format|git status -s| | ||
| - | |||
| - | ==== Make Commits ==== | ||
| - | ^Task^Command^ | ||
| - | |Make a commit (and open text editor to write message)|git commit| | ||
| - | |Make a commit|git commit -m ' | ||
| - | |Commit all unstaged changes|git commit -am ' | ||
| - | |||
| - | ==== Move Between Branches ==== | ||
| - | ^Task^Command^ | ||
| - | |Switch branches|git switch < | ||
| - | |Create a branch|git branch < | ||
| - | |List branches|git branch| | ||
| - | |List branches by most recently committed to|git branch --sort=-committerdate| | ||
| - | |Delete a branch|git branch -d < | ||
| - | |Force delete a branch|git branch -D < | ||
| - | |||
| - | ==== Diff Staged/ | ||
| - | ^Task^Command^ | ||
| - | |Diff all staged and unstaged changes|git diff HEAD| | ||
| - | |Diff just staged changes|git diff --staged| | ||
| - | |Diff just unstaged changes|git diff| | ||
| - | |||
| - | ==== Diff Commits ==== | ||
| - | ^Task^Command^ | ||
| - | |Show diff between a commit and its parent|git show < | ||
| - | |Diff two commits|git diff < | ||
| - | |Diff one file since a commit|git diff < | ||
| - | |Show a summary of a diff|git diff < | ||
| - | |||
| - | ==== Discard Your Changes ==== | ||
| - | ^Task^Command^ | ||
| - | |Delete unstaged changes to one file|git restore < | ||
| - | |Delete all staged and unstaged changes to one file| git restore --staged --worktree < | ||
| - | |Delete all staged and unstaged changes|git reset --hard| | ||
| - | |Delete untracked files|git clean| | ||
| - | |' | ||
| - | |||
| - | ==== Edit History ==== | ||
| - | ^Task^Command^ | ||
| - | |" | ||
| - | |Squash the last 5 commits into one|git rebase -i HEAD~6 \\ Then change " | ||
| - | |Undo a failed rebase|git reflog BRANCHNAME \\ Then manually find the right commit ID in the reflog, then run: \\ git reset --hard < | ||
| - | |Change a commit message (or add a file you forgot)|git commit --amend| | ||
| - | |||
| - | ==== Code Archaeology ==== | ||
| - | ^Task^Command^ | ||
| - | |Show the files under control|git ls-files| | ||
| - | |Look at a branch' | ||
| - | |Show every commit that modified a file| git log < | ||
| - | |Show every commit that modified a file, including before it was renamed| git log --follow < | ||
| - | |Find every commit that added or removed some text|git log -G banana| | ||
| - | |Show who last changed each line of a file|git blame < | ||
| - | |||
| - | ==== Combine Diverged Branches ==== | ||
| - | ^Task^Command^ | ||
| - | |Combine with Rebase|git switch banana \\ git rebase main \\ \\ Before \\ {{ : | ||
| - | |Combine with Merge|git switch main \\ git merge banana \\ \\ Before \\ {{ : | ||
| - | |Combine with Square Merge|git switch main \\ git merge --squash banana \\ git commit \\ \\ Before \\ {{ : | ||
| - | |Bring a branch up to date with another branch \\ (aka " | ||
| - | |Copy one commit onto the current branch| git cherry-pick < | ||
| - | |||
| - | ==== Restore an Old File ==== | ||
| - | ^Task^Command^ | ||
| - | |Get the version of a file from another commit|git checkout < | ||
| - | |||
| - | ==== Remote Repositories ==== | ||
| - | ^Task^Command^ | ||
| - | |Add a Remote|git remote add < | ||
| - | |Push the main branch to the remote origin|git push origin main| | ||
| - | |Push the current branch to its remote " | ||
| - | |Push a branch that you've never pushed before|git push -u origin < | ||
| - | |Force push|git push --force-with-lease| | ||
| - | |Push tags|git push --tags| | ||
| - | |Pull changes (but don't change any of your local branches)|git fetch origin main| | ||
| - | |Pull changes and then rebase your current branch|git pull --rebase| | ||
| - | |Pull changes and then merge them into your current branch|git pull origin main OR \\ git pull| | ||
| - | |||
| - | ==== Important Files ==== | ||
| - | ^Item^Location^ | ||
| - | |Local git config|.git/ | ||
| - | |Global git config|~/ | ||
| - | |List of files to ignore|.gitignore| | ||
| - | |||
| - | ==== Links ==== | ||
| - | * [[https:// | ||
computing/git.1777227743.txt.gz · Last modified: by oscar
