Skip to content

Instantly share code, notes, and snippets.

@ptotaram
Last active January 26, 2016 16:50
Show Gist options
  • Save ptotaram/9538131 to your computer and use it in GitHub Desktop.
Save ptotaram/9538131 to your computer and use it in GitHub Desktop.
Helpful Git Commands

#Helpful Git Commands

###Add to previous commit git commit --amend --reuse-message

###Change the commit message git commit --amend

###Stash Specific File git stash -p

###Delete untracked files git clean -f However you will want to do a dry run before hand '-n' or '--dry-run' will do this

###Delete Local Branches git branch -D

###Delete Remote Branches git push origin --delete

###Mass Delete Branches git branch | grep "term_within_branchname" | xargs -n 1 git branch -D This is given that you strategically named your branch

Warning

This command deletes unmerged branches

###Cherry Pick git cherry-pick

This gives the log of a different branch (useful in attaining commit hash) git log

###Delete a tag git tag -d

###Stage specific changes within a file git add --patch

###Delete branches from your origin DB that were deleted git fetch -p origin

###Rename Files git mv source destination Be sure to use git, or else your commit will have 2 file changes (1 removed and one added) rather than just 1 renamed file

###Clean deleted remote branches git remote prune <remote(origin)>

###Delete Commits git rebase -i The commitHash here is the hash of the last commit you want to keep This opens your set git editor (in your .gitconfig) and lists all the commits after the you set. You just delete the commits you don't want

###Ignore file mode (permissions) change git config core.fileMode false

###Restore file to previous version git checkout abcde file/to/restore

###Reset local branch to remote head git reset --hard remote/branch You may want to check out to a branch to back up what you've already done

@ptotaram
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment