Skip to content

Instantly share code, notes, and snippets.

@vatz88
Last active January 17, 2024 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vatz88/7db6c4c375551b7685c12ead5f91f410 to your computer and use it in GitHub Desktop.
Save vatz88/7db6c4c375551b7685c12ead5f91f410 to your computer and use it in GitHub Desktop.
Helpful git commands
<!-- delete branch from github and locally -->
git push origin --delete <branch-name>
git branch -d <branch-name>
<!-- add remote to current branch -->
git branch --set-upstream-to <remote-name>
<!-- Undo last commit -->
git reset HEAD~
<!-- squashing commits -->
git reset --soft HEAD~3 // squash last three commits
git commit -m "New message for the combined commit"
git push origin +name-of-branch <!-- + is for force if the commits are already pushed to github -->
<!-- see changed files in unpushed commit -->
git diff --stat origin/master
<!-- Reset local master brach as per remote branch -->
git reset --hard origin/master
<!-- Restore file from a remote branch -->
git restore --source origin/master -- [file path]
<!-- git add only the files already in stage -->
git diff --name-only --cached | xargs git add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment