Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions git-cheatsheet.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#set page(
width: 297mm,
height: 210mm,
margin:(
top: 0.5cm,
bottom: 0.5cm,
left: 0.5cm,
right: 0.5cm,
),
columns: 2,
)
#set text(font: "Times New Roman", size: 8pt)
#set heading(numbering: "1.")
#show link: set text(fill: blue)
#show strong: set text(weight: "semibold")

#align(center, text(14pt)[*Git Cheatsheets*])


*Installation* \
*macOS*
- 'xcode -select --install' or 'brew install git'
- Verify: 'git --version'
*Linux*
- Debian/Ubuntu: 'sudo apt install git'
- Fedora: 'sudo dnf install git'
- Arch: 'sudo pacman -S git'
- Verify: 'git --version'
*Windows*
- Download installer from [https://git-scm.com/download/win]
= Quick Start
#table(
table.header([*Command*], [*Description*]),
columns: 2,
align: horizon,
inset: 6pt,
rows: auto,
[`git config --global user.name "Your Name"`],[ Set your display name for commits.],
[`git config --global user.email "you@example.com"` ],[Set your email for commits.],
[`git config --global init.defaultBranch main` ], [Use `main` for new repos.],
[`git config --global color.ui auto`],[& Enable colored CLI output. ],
[`git init [project-name]`],[ Initialize a new repo in the current directory],
[`git clone <project-url>`],[Create a local copy of remote repo],
[`git remote add origin <url>`],[Add a remote named `origin`],
[`git remote -v`], [Show remotes and their URLs.]
)

/*
Commands for Branch & Merging section;
git banch, git branch [branch-name], git checkout, git merge []branch-name], git log
*/

= Branch & Merge
#table(
table.header([*Command*],[*Description*]),
columns: 2,
align: horizon,
inset:6pt,
rows: auto,
[`git branch`],[List local branches.],
[`git branch <name>`],[Create a new branch.],
[`git switch <name>`],[Switch to an existing branch.],
[`git switch -c <name>`],[Create and switch to a new branch.],
[`git merge <branch>`],[Merge <branch> into the current branch.],
[`git rebase <base>`],[Replay current commits on top of <base>.],
[`git log --oneline --graph --decorate`],[View compact commit graph.],

)


#colbreak()
= Inspect & Compare
#table(
table.header([*Command*],[*Description*]),
columns: 2,
align : horizon,
inset: 6pt,
rows: auto,
[`git log`],[Show the commit history for the currently active branch.],
[`git log branchB..branchA`],[Show the commits on branchA that are not on branchB.],
[`git log --follow [file]`],[Show the commits that changed file, even across renames.],
[`git diff branchB...branchA`],[Show the diff of what is in branchA that is not in branchB.],
[`git show [SHA]`],[Show any object in Git in human-readable format.],
)


= Share & Update
#table(
table.header([*Command*],[*Description*]),
columns: 2,
inset:6pt,
rows: auto,
align: horizon,
[`git fetch`],[Download updates from remote (no integrate).],
[`git pull`],[Fetch and integrate into current branch.],
[`git push`],[Upload local commits to remote.],
[`git push -u origin <branch>`],[Push and set upstream for <branch>.],
[`git fetch --prune`],[Remove refs deleted on remote.],
)

= Rewriting Git History
#table(
table.header([*Command*],[*Description*]),
columns: 2,
align: horizon,
inset:6pt,
rows: auto,
[`git commit --amend`],[Edit the last commit message or content.],
[`git rebase -i <base>`],[Interactively rebase commits onto <base>.],
[`git reset --soft <commit>`],[Move HEAD, keep changes staged.],
[`git reset --hard <commit>`],[Move HEAD, discard all changes.],
[`git revert <commit>`],[Create a new commit that undoes <commit>.],

)

= Temporary Commits: storing your temp work
#table(
table.header([*Command*],[*Description*]),
columns: 2,
align: horizon,
inset:6pt,
rows: auto,
[`git stash`],[Save changes for later, keep working directory clean.],
[`git stash pop`],[Re-apply the most recent stash and remove it.],
[`git stash list`],[Show all stashed changes.],
[`git stash drop`],[Delete a stash entry.],
)

#colbreak()
// tagging commits
= Tagging Commits
#table(
table.header([*Command*],[*Description*]),
columns: 2,
inset: 6pt,
align: horizon,
rows: auto,
[`git tag`],[List all tags in the repository.],
[`git tag [name] [commit sha]`],[Create a new tag at the specified commit (or HEAD if omitted).],
[`git tag -d [name]`],[Delete a local tag.],
[`git push origin [name]`],[Push a specific tag to the remote repository.],
[`git push origin --tags`],[Push all local tags to the remote repository.],
)