Skip to main content
๐Ÿ—Ž Refs:
๐Ÿ“œOfficial Document
Atlassian Git Tutorial
Learn Git Branching
Visual Git

Configuring user information

Set global name

git config --global user.name "Americio Hoag"

Set global email

git config --global user.email "[email protected]"

Enable automatic command line coloring

git config --global color.ui auto

INIT/CLONE REPO

Initialize a Git repository

git init

Clone remote repository

git clone https://github.com/OliverKain/obsidian-vault

STASH

Stash changes

git stash

List stash

git stash list

Pop stash

git stash pop

Drop the top of stash

git stash drop

STAGE & COMMIT

Show modified files in the working directory

git status

Stage file(s)

git add path/to/file1.md [path/to/file2.md path/to/file3.md]

Un-stage file(s)

# use git-restore
git restore --staged path/to/file1.md [path/to/file2.md path/to/file3.md]

# use git-reset
git reset path/to/file1.md [path/to/file2.md path/to/file3.md]
More advanced usage for git-reset here

Show changed, not staged differences

git diff

Show staged, not committed differences

git diff --staged

Commit staged changes

git commit -m "Add new .md files"

BRANCH & MERGE

List branches

git branch # * indicates current branch

Branching at the current commit

git branch new-branch-name

Checkout a branch

git checkout existing-branch

Merge a branch into the current branch

git merge need-to-merge-branch

REMOTE INTERACTION

Retrieving updates from another repository:
  • git remote add [alias] [url]: Add a Git URL as an alias.
  • git fetch [alias]: Fetch down all branches from that Git remote.
  • git merge [alias]/[branch]: Merge a remote branch into your current branch to bring it up to date.
  • git push [alias] [branch]: Transmit local branch commits to the remote repository branch.
  • git pull: Fetch and merge any commits from the tracking remote branch.

(WIP) TRACKING PATH CHANGES

Versioning file removals and path changes:
  • git rm [file]: Delete the file from the project and stage the removal for commit.
  • git mv [existing-path] [new-path]: Change an existing file path and stage the move.

(WIP) REWRITE HISTORY

Rewriting branches and updating commits:
  • git rebase [branch]: Apply any commits of the current branch ahead of specified one.
  • git reset --hard [commit]: Clear staging area, rewrite working tree from specified commit.

(WIP) INSPECT & COMPARE

Examining logs, diffs, and object information:
  • git log: Show the commit history for the currently active branch.
  • git log branchB..branchA: Show commits on branchA that are not on branchB.
  • git diff branchB...branchA : Show differences in content between two branches.

(WIP) IGNORING PATTERNS

Preventing unintentional staging or committing of files:
  • Use .gitignore: Save patterns as strings or wildcards to ignore specific files or directories.
This cheat sheet serves as an essential guide for both beginners and experienced users to navigate common Git commands effectively.