Skip to content

Instantly share code, notes, and snippets.

@DaddyMoe
Last active February 19, 2020 16:59
Show Gist options
  • Save DaddyMoe/28175deb1407a044a1544072ab66ac75 to your computer and use it in GitHub Desktop.
Save DaddyMoe/28175deb1407a044a1544072ab66ac75 to your computer and use it in GitHub Desktop.
most use GIT commands I always seems to forget

Undoing the Last Commit

git reset --soft HEAD~1
  • Reset will rewind your current HEAD branch to the specified revision.

  • Effectively making our last commit undone.

  • The --soft flag: ensures undone revisions are preserved.

    git reset --hard HEAD~1

  • If you don't want to keep these changes

Undoing Multiple Commits to any previous revision:

$ git reset --hard XXXXDDGDGDG

  • undoes all commits that came after the one you returned to here XXXXDDGDGDG

Delete all local branches except master

git branch | grep -v "master" | xargs git branch -D 

set alais

alias gbr="git branch | grep -v "master" | xargs git branch -D"

To delete a local branch

git branch -d the_local_branch

To remove a remote branch (if you know what you are doing!)

git push origin :the_remote_branch

connect local repo with remote repo

git remote add origin <remote_repo_url>
git push --all origin

Set all branches to automatically use emote repo when git pull:

git push --all --set-upstream origin

How to squash already pushed commits

git rebase -i origin/development~<index-of-required-commit-range>
git push origin +development  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment