Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Last active November 27, 2024 14:01
Show Gist options
  • Save allysonsouza/caafdc0856bb4682978dbdf0603b4d71 to your computer and use it in GitHub Desktop.
Save allysonsouza/caafdc0856bb4682978dbdf0603b4d71 to your computer and use it in GitHub Desktop.
[Git Commands] Git commands #Git #snippets

Git Commands

General

Init repository

git init

Discard unstaged changes

git restore .

#or

git restore path/to/file/to/revert

List commits

git log

Use ↑↓ to navigate, and q to exit.

Checkout

Checkout a specific commit

git checkout <commit-code> 

Return to latest commit

git checkout -

Checkout creating a new branch

git checkout -b <branch-name>

Delete

Delete local branch

git branch -D <branch-name>

Delete remote branch

git push <remote> --delete <branch-name>

Delete branches that have been merged

Ref: https://graphite.dev/guides/git-delete-local-branch-been-merged

git branch --merged | grep -v "^\*\\|main|staging|dev" | xargs -n 1 git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment