Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active February 19, 2021 05:00
Show Gist options
  • Save abelcallejo/7bef0aced7e29cfbcf1d66e55b5d3d06 to your computer and use it in GitHub Desktop.
Save abelcallejo/7bef0aced7e29cfbcf1d66e55b5d3d06 to your computer and use it in GitHub Desktop.
GIT cheatsheet

GIT cheatsheet

Rebasing

# Get an updated version from the remote repository
git checkout master
git pull

# Adjust the heads based on the master branch
git checkout my-feature-branch
git rebase master

Ignoring local changes

git update-index --assume-unchanged path/to/ignored.txt

Note: This only affects the current branch

Reverting ignored local changes

git update-index --no-assume-unchanged path/to/ignored.txt

Stashing

# Handpick files to stash
git add path/to/be/stashed.txt

# Stash it
git stash push -m "description of this set of stashed files"

Applying stashes

# List the stashes
git stash list

# Apply a certain stash
git stash apply stash@{1}

Listing all the files inside the a stash

git stash show stash@{0} --name-only

Showing the raw content of a file inside a stash

git show stash@{0}:/path/to/my/file

Resetting a local branch

Let's say you want to reset the local branch master and make a copy of the remote repository

git branch -D master
git branch --set-upstream-to=origin/master master
git checkout master
git pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment