Last active
May 3, 2024 03:00
-
-
Save locnt19/4f3ae754d4f9d42710b71d417f308b98 to your computer and use it in GitHub Desktop.
Useful Git commands.
This file contains 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
# SETTING GLOBAL INFO: | |
git config --global user.email "you@example.com" | |
git config --global user.name "Your Name" | |
# MOVE/RENAME FILE: | |
git mv <source> <directory>/<new_source_name> | |
# SEARCH BRANCH: | |
git branch -r | grep -i <query> | |
# DELETE BRANCH: | |
- Local: git branch -d "branch_name" | |
- Remote: git push origin --delete "branch_name" | |
# REBASE DATA: | |
git rebase "branch_name" | |
:wq | |
git rebase --continue | |
git push --force | |
# PUSH LOCAL BRANCH TO REMOTE: | |
git push --set-upstream origin "branch_name" | |
# CHANGE BRANCH NAME: | |
git checkout "branch_name_old" | |
git branch -m "branch_name_new" | |
git push origin :"branch_name_old" "branch_name_new" | |
git push origin -u "branch_name_new" | |
# DELETE ALL LOCAL BRANCH: | |
for b in `git branch --merged | grep -v \*`; do git branch -D $b; done | |
# CHANGE COMMIT MESSAGE: | |
git commit --amend -m "New commit message" | |
# GIT REVERT: | |
git revert commit_hash | |
# STASH ALL BUT KEEP STAGED: | |
git stash push --keep-index --include-untracked -m "message" | |
# STASH STAGED CHANGES ONLY | |
git stash push -m "message" --staged | |
# SWITCH MAIN BRANCH: | |
git switch - | |
# CHECKOUT OLDER COMMIT & CREATE NEW BRANCH: | |
git checkout -b "branch_name" "commit_hash" | |
# REMOVE UNTRACKED FILES | |
git clean -f -d | |
# Install Dependencies Legacy Peer Deps | |
npm install --legacy-peer-deps | |
yarn install --peer | |
# Revert Multiple Local Commits | |
git reset --soft ORIG_HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment