Skip to content

Instantly share code, notes, and snippets.

@0xntpower
Created September 14, 2024 20:16
Show Gist options
  • Select an option

  • Save 0xntpower/3ccdc41f533fc3fbf6f5e65752fd0ec5 to your computer and use it in GitHub Desktop.

Select an option

Save 0xntpower/3ccdc41f533fc3fbf6f5e65752fd0ec5 to your computer and use it in GitHub Desktop.
GIT CHEAT SHEET

Getting information about current local repo

git status
git branch

Get in sync with another branch (rebasing)

This tactic will make our branch, branch from the new head of the other branch effectively changing the commit history.

git checkout <feature-branch>
git rebase <branch-to-synch-to>
git rebase <branch-to-synch-to> --interactive # to also squash commit

Get in synch with another branch (merging)

This tactic will effectively merge the changes from the other branch into our current working directory creating new merge commits to add the changes.

git fetch
git merge origin/main
git pull origin <current-branch>

Upload new changes

git add .
git commit -m "implemented new feature"
git push origin <branch-your-at>

Revert the last commit (that has been pushed to remote)

Provide the id of the commit itself that you want to revert

git revert <commit-ID> -m "reverting last commit"

Revert a commit that has not been pushed

Provide the id of the commit that you want to reset back to

git reset (commit-ID) # keep the committed changes
git reset (commit-ID) --hard # discard the committed changes (more dangerous)

Not sure about a merge conflict? Abort using

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