Skip to content

Instantly share code, notes, and snippets.

@locnt19
Last active August 19, 2025 20:54
Show Gist options
  • Select an option

  • Save locnt19/4f3ae754d4f9d42710b71d417f308b98 to your computer and use it in GitHub Desktop.

Select an option

Save locnt19/4f3ae754d4f9d42710b71d417f308b98 to your computer and use it in GitHub Desktop.
Useful commands.

Useful commands

SETTING GLOBAL INFO

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

SHOW GIT CONFIG WITH SCOPE

git config --list --show-scope

# Edit Git config Global
nano ~/.gitconfig

# Edit Git config local repo
nano .git/config

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 COMMIT

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

Cherry Pick

git cherry-pick A
git cherry-pick A^..B`

Count total code lines in the project

git ls-files | xargs wc -l

Dump MySQL in Docker

docker exec container_name \
  sh -c 'mysqldump -u root -p<password> database_name > /tmp/database_name.sql'

docker cp container_name:/tmp/database_name.sql ./database_name.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment