0% found this document useful (0 votes)
40 views

Git Cheat Sheet

Uploaded by

atairineu12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Git Cheat Sheet

Uploaded by

atairineu12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

getting started move between diff commits trash your changes combine diverged branches add a remote

branches
start a new repo: show diff between a commit
delete all staged and how the branches look before: git remote add $NAME $URL
git init switch branches: and its parent:
unstaged changes to one file:
clone an existing repo: git switch $NAME OR git show $COMMIT_ID main
git checkout $NAME git checkout HEAD $FILE
git clone $URL show diff between a merge banana push your changes
create a branch: commit and its merged parents: delete unstaged changes to
one file: combine with rebase:
git switch -c $NAME OR git show --remerge-diff push the main branch
git switch banana to the remote origin:
$COMMIT_ID git checkout $FILE
know where you are git checkout -b $NAME git rebase main git push origin main
diff two commits:
delete all staged and
list branches: git diff $COMMIT_ID $COMMIT_ID unstaged changes:
main banana push a branch to the remote
git status
git branch origin that you've never pushed
just show diff for one file: git reset --hard before:
"lost"
delete a branch git diff $COMMIT_ID $FILENAME git push -u origin $NAME
delete untracked files: combine with merge:
prepare to commit git branch -d $NAME
show a summary of a diff: git clean git switch main push the current branch to
force delete a branch: git merge banana its remote "tracking branch":
add untracked file: git branch -D $NAME git diff $COMMIT_ID --stat "stash" all staged and git push
git commit
(or unstaged changes) git show $COMMIT_ID --stat unstaged changes (pretend I
git add $FILE list branches by most might get them back later) force push:
main
recently committed to: git stash git push --force-with-lease
add ALL untracked files diff staged/unstaged changes
and unstaged changes: git branch banana push tags:
--sort=-committerdate combine with squash merge:
git push --tags
git add . diff all staged and
unstaged changes:
edit history
git switch main
choose which parts of a git diff HEAD
look at a branch's git merge --squash banana
file to stage: "undo" the most recent commit pull changes
git add -p history (keep your working directory git commit
diff just staged changes:
the same): fetch changes:
delete or move file: log the branch git diff --staged main
git reset HEAD^ (but don't change any
git rm $FILE git log main diff just unstaged changes: of your local branches)
git mv $OLD $NEW squash the last 5 commits
git diff into one:
banana git fetch origin main
show how two branches
tell git to forget about a relate to each other: git rebase -i HEAD^^^^^^ fetch changes and then merge
file without deleting it: git log --graph a b bring a branch up to date them into your current branch:
configure git (and change "pick" to
git rm --cached $FILE "fixup" for any commit I with another branch git pull origin main OR
one line log:
set a config option: want to combine with the (aka "fast-forward merge") git pull
unstage everything: git log --oneline git config user.name 'Julia' previous one)
git reset HEAD main fetch changes and then
name value banana
undo a failed rebase: rebase your current branch:
code archaeology see all possible config options: git reflog BRANCHNAME git pull --rebase
make commits man git-config do a painstaking search git switch main
show who last changed git reset --hard $COMMIT_ID fetch all branches:
each line of a file:
git merge banana
make a commit: set option globally: git fetch --all
git blame $FILENAME change a commit message: banana
(and open a text editor git config --global ...
to write the message) (or add a file you forgot) main
show every commit that
git commit add an alias: git commit --amend ways to refer to a commit
modified a file:
git config alias.st status
make a commit: git log $FILENAME every time we say $COMMIT_ID,
copy one commit onto you can use any of these:
git commit -m 'message'
find every commit that important git files another branch
added or removed some restore an old file before: a branch main
commit all unstaged main
changes: text: local git config: get the version of a file a tag v0.1
git commit -am 'message' git log -S banana .git/config from another branch or banana
a commit ID 3e887ab
commit a remote branch origin/main
global git config:
git checkout $COMMIT_ID $FILE git cherry-pick $COMMIT_ID current commit HEAD
~/.gitconfig
git has 17 million options OR after: 3 commits ago HEAD^^^
list of files to ignore: main 3 commits ago HEAD~3
but this is how I use it! git restore $FILE
.gitignore --source $COMMIT_ID banana

You might also like