0% found this document useful (0 votes)
86 views1 page

Git - Dark

This document provides a cheat sheet for common Git commands. It summarizes commands for setting up a Git repository, working with branches, reviewing changes, rebasing, merging, tagging commits, stashing changes, and synchronizing repositories. Key sections include commands for branches, reviewing changes, rebasing, merging, deleting stashes, and fetching/pulling from remote repositories.

Uploaded by

Diego Do Santos
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)
86 views1 page

Git - Dark

This document provides a cheat sheet for common Git commands. It summarizes commands for setting up a Git repository, working with branches, reviewing changes, rebasing, merging, tagging commits, stashing changes, and synchronizing repositories. Key sections include commands for branches, reviewing changes, rebasing, merging, deleting stashes, and fetching/pulling from remote repositories.

Uploaded by

Diego Do Santos
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

Git Cheat Sheet Rebasing Review your Repo Delete stash at index 1.

Omit
stash@{n} to delete last stash made
Rebase feature branch onto main (to List new or modified files not yet
incorporate new changes made to committed $ git stash drop stash@{1}
Setup Branches main). Prevents unnecessary merge
$ git status Delete all stashes
Set the name and email that will be commits into feature, keeping history
List all local branches. Add -r flag to
attached to your commits and tags clean List commit history, with respective $ git stash clear
show all remote branches. -a flag for
all branches. IDs
$ git config --global
user.name "Danny Adams" $ git branch $ git log --oneline
Synchronizing
$ git config --global
Create a new branch Show changes to unstaged files. For
user.email "my- Add a remote repo
changes to staged files, add --cached
email@gmail.com"
$ git branch <new-branch> $ git checkout feature option $ git remote add <alias>
$ git rebase main <url>
Start a Project Switch to a branch & update the
working directory Interatively clean up a branches
$ git diff
View all remote connections. Add -v
Create a local repo (omit <directory> commits before rebasing onto main Show changes between two commits flag to view urls.
to initialise the current directory as a $ git checkout <branch>
git repo $ git rebase -i main $ git diff commit1_ID $ git remote
Create a new branch and switch to it
commit2_ID
Interatively rebase the last 3 commits Remove a connection
$ git init <directory> $ git checkout -b <new- on current branch
Download a remote repo
branch> Stashing $ git remote remove <alias>
$ git rebase -i Head~3
Delete a merged branch Store modified & staged changes. To Rename a connection
$ git clone <url> include untracked files, add -u flag.
$ git branch -d <branch>
Undoing Things For untracked & ignored files, add -a $ git remote rename <old>

Make a Change flag. <new>


Delete a branch, whether merged or Move (&/or rename) a file & stage
$ git stash Fetch all branches from remote repo
Add a file to staging not move
(no merge)
$ git branch -D <branch> $ git mv <existing_path> As above, but add a comment.
$ git add <file> $ git fetch <alias>
<new_path>
$ git stash save "comment"
Stage all files Add a tag to current commit (often Fetch a specific branch
used for new version releases) Remove a file from working directory
Partial stash. Stash just a single file, a
& staging area, then stage the
$ git add . collection of files, or individual $ git fetch <alias> <branch>
$ git tag <tag-name> removal
changes from within files
Commit all staged files to git Fetch the remote repo's copy of the
$ git rm <file> current branch, then merge
$ git stash -p
$ git commit -m "commit
message"
Merging Remove from staging area only
List all stashes $ git pull
Merge branch a into branch b. Add -- $ git rm --cached <file>
Add all changes made to tracked files no-ff option for no-fast-forward $ git stash list Move (rebase) your local changes
& commit merge View a previous commit (READ only) onto the top of new changes made to
Re-apply the stash without deleting it the remote repo (for clean, linear
$ git commit -am "commit
$ git checkout <commit_ID> history)
message" $ git stash apply
Create a new commit, reverting the $ git pull --rebase <alias>
Basic Concepts changes from a specified commit Re-apply the stash at index 2, then
delete it from the stash list. Omit Upload local content to remote repo
main: default development $ git revert <commit_ID> stash@{n} to pop the most recent
branch stash. $ git push <alias>
$ git checkout b Go back to a previous commit &
origin: default upstream repo
$ git merge a delete all commits ahead of it (revert $ git stash pop stash@{2} Upload to a branch (can then pull
HEAD: current branch
HEAD^: parent of HEAD is safer). Add --hard flag to also request)
Merge & squash all commits into one delete workspace changes (BE VERY Show the diff summary of stash 1.
HEAD~4: great-great new commit Pass the -p flag to see the full diff.
grandparent of HEAD CAREFUL) $ git push <alias> <branch>

By @DoableDanny $ git merge --squash a $ git reset <commit_ID> $ git stash show stash@{1}

You might also like