Skip to content

Instantly share code, notes, and snippets.

@Alex-Just
Last active February 20, 2019 17:27
Show Gist options
  • Save Alex-Just/5f77ed4a6017de8b01a6b73e58222810 to your computer and use it in GitHub Desktop.
Save Alex-Just/5f77ed4a6017de8b01a6b73e58222810 to your computer and use it in GitHub Desktop.
# Reset/checkout a single file from remote origin `branch`
git fetch --all
git checkout origin/branch -- path/to/file
# Reset local repository branch to be just like remote repository HEAD
git fetch origin && git reset --hard origin/develop
# Update current branch from dev
# `git checkout dev; git pull origin dev; git checkout branch; git rebase dev`
git pull --rebase origin develop
git pull --rebase origin stage
# Update current branch from dev when there're uncommited changes
git stash && git pull --rebase origin develop && git stash apply
# Delete a local branch
git branch -d the_local_branch
# Remove a remote branch
git push origin :BRANCH
# New branch with local unstaged changes in the working directory
git checkout -b experiment
# How to remove a file from git source control but not delete it
git rm --cached file
# Stashing
git stash # = `git stash save` record the current state of the working directory
git stash list # list stashed modifications
git stash apply # restore (potentially on top of a different commit)
# Delete the last pushed commit
git push origin +hash^:BRANCH
# Set upstream branch
git branch BRANCH -u origin/BRANCH
# Revert repository to a commit
git revert --no-commit hash..HEAD
git commit
# Remove local branches except for "master"
git branch | grep -v "master" | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment