Created
July 21, 2018 10:41
-
-
Save Otteri/5dd7cb528de15bb258aa98506a8713d6 to your computer and use it in GitHub Desktop.
Some often needed git commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
# GENERAL # | |
########################### | |
# Show filenames that have changed in the last <n> commits: | |
git diff --name-only HEAD HEAD~<n> | |
# Git copy current branch status to master w/o doing merge | |
git checkout master | |
git checkout other_branch . | |
# Rewrite latest unpushed commit | |
git commit --amend | |
# Reset tracked files to head | |
git reset --hard # Reset everything | |
git reset --soft # Reset only unpushed commits | |
# Reset specific file(s) | |
git checkout HEAD -- <file(s)> | |
# Remove untracked files from working tree | |
git clean | |
git clean -n # Show what will be deleted | |
git clean -d # Remove directories | |
git clean -x # remobe ignored files | |
# Add bunch of files to commit | |
git add -A # Stages All | |
git add . # Stages new and modified, without deleted | |
git add -u # Stages modified and deleted, without new | |
########################### | |
# BRANCH # | |
########################### | |
# Git list all branches | |
git branch -a | |
########################### | |
# STASH # | |
########################### | |
# Clear stash (all at once) | |
git stash clear | |
# List filenames from latest stash | |
git stash show --name-only | |
# List stashes | |
git stash list | |
########################### | |
# SUBMODULES # | |
########################### | |
# Update all submodules | |
git submodule update --recursive --init | |
# Do something to all submodules: | |
git submodule foreach <git command> | |
# Some example combinations: | |
git submodule foreach --recursive git clean -xfd | |
git submodule foreach --recursive git reset --hard | |
git submodule update --init --recursive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment