Great tutorial: https://www.atlassian.com/git/tutorials/saving-changes/git-stash
Knowing how to leverage git stash
is a superpower and the following commands will allow you to do just that:
- Basic use (will store current changes to the stash):
git stash
- Save untracked files by:
git stash -u
- View(list) your stash:
git stash list
- Store a stash with a message:
git stash save "fire"
- Pop a stash(will pop the recent most stash):
git stash pop
- Pop a specific stash:
git stash pop <stash_id>
- Apply a stash without removing it(will apply the recent most stash):
git stash apply
- Apply a specific stash without removing it:
git stash apply <stash_id>
git rm --cached <file>
-
Add remote from original repository in your forked repository:
cd into/cloned/fork-repo # remote name can be anything you want git remote add <remote_name> git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git git fetch <remote_name>
-
Updating your fork from original repo to keep up with their changes:
# for branch master (you can change this for any branch) git pull <remote_name> master
-
To update the remote fork on GitHub (or any other git hosting site):
# this assumes that the remote forks name is origin (which is usually the case) # branch name can be changed up to your liking git push origin master
-
Regular (will open selected editor for editing commit message):
git commit --amend
-
Editing the commit message directly:
git commit --amend -m "<your new message>"
-
Without editing commit message:
git commit --amend --no-edit
-
Delete local tag:
git tag -d <tag>
-
Delete remote tag (for eg. on GitHub)
git push --delete origin <tag>
git reset --hard <commit>
git push -f <remote_name> master
git diff
-
If you have not yet indexed (git add) your changes:
git checkout -- path/to/folder
-
If changes are indexed then you need to reset that first:
git reset -- path/to/folder git checkout -- path/to/folder
git remote update origin --prune
git branch -m <new_name>
git reset HEAD~