Skip to content

Instantly share code, notes, and snippets.

@felipecrs
Last active April 4, 2023 14:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save felipecrs/5ebaebf2560ce64a523977e61636ff8c to your computer and use it in GitHub Desktop.
Save felipecrs/5ebaebf2560ce64a523977e61636ff8c to your computer and use it in GitHub Desktop.
Git commands snippets

Track all files to commit

git add .

Commit

git commit

Update local branch master

git pull origin master

Update local branch master when you have commits pending push

git pull --rebase origin master

Push changes to master branch on remote

git push origin master

Force push changes to master branch on remote

git push --force origin master

Restore repository to a clean state, deleting even the files ignored (at the end you'll have a repository just like a fresh git clone)

git clean -fdx

Save changes for applying latter

git stash

Apply saved changes

git stash apply

Create local branch based on current change

git checkout -b branch_name

Go to branch master

git checkout master

Reset to master branch from remote (delete local commits on master)

git reset --hard origin/master

Delete local branch

git branch --delete branch_name

Create local tag based on current change

git tag v0.0.1

Delete local tag

git tag --delete v0.0.1

Push branch or tag on remote

git push origin branch_or_tag_name

Delete branch or tag on remote

git push origin :branch_or_tag_name

Apply a change on top of the current change

git cherry-pick change_id

git rm -r --cached .
git add .
git commit -m ".gitignore fix"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment