Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Last active November 24, 2021 06:52
Show Gist options
  • Save hoangitk/69aa78c6f24690515f2dd954a853d930 to your computer and use it in GitHub Desktop.
Save hoangitk/69aa78c6f24690515f2dd954a853d930 to your computer and use it in GitHub Desktop.
[Git command] #git #collection

Git Commands

How to remove local untracked files from the current Git branch

  • List of untracked files
git clean -n
  • Delete untracked files
git clean -f
  • To remove directories
git clean -f -d or git clean -fd
  • To remove ignored files
git clean -f -X or git clean -fX
  • To remove ignored and non-ignored files
git clean -f -x or git clean -fx

How to Delete a Git Branch Both Locally and Remotely

  • Delete branch locally
git branch -d localBranchName

The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.

  • Delete branch remotely
git push origin --delete remoteBranchName

Force git to run post-receive hook, even if everything is “up-to-date”

git commit --amend --no-edit
git push -f

Stop tracking files that should be ignored

git rm -r --cached . 
git add .
git commit -am "Remove ignored files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment