Skip to content

Instantly share code, notes, and snippets.

@bhuvidya
Last active September 21, 2023 13:42
Show Gist options
  • Save bhuvidya/26634acebe37b25df093b65f52b47c32 to your computer and use it in GitHub Desktop.
Save bhuvidya/26634acebe37b25df093b65f52b47c32 to your computer and use it in GitHub Desktop.
Some handy git commands / operations / workflows.

Git Handy Commands

Delete a local feature branch, the remote tracking branch, and the remote branch

$ git branch -d feature/blah
$ git branch -d -r origin/feature/blah
$ git push origin :feature/blah

Delete a branch on an upstream

$ git push origin :feature/blah
$ git push origin :b55bc88

Force an upstream branch to match a local one

$ git push --force -u origin feature/blah

Force a local branch to match an upstream one

$ git fetch origin
$ git branch my-saved-branch
# this example is for develop branch
# make sure you are have develop checked out locally first, then...
$ git reset --hard origin/develop

Manual rebase of a feature branch

Checkout the feature branch that needs rebasing:

$ git checkout feature/blah

Then rebase onto develop:

$ git rebase develop

Then force upstream feature branch to match local one:

$ git checkout develop
$ git push --force -u origin feature/blah    

Checkout a remote feature branch for the first time, and remote-track it.

$ git checkout -b feature/blah --track origin/feature/blah
$ git submodule update --init

Cat a file to stdout

$ git cat-file -p commit:file-spec

List all the commits that included changes to a file

$ git log --follow -- filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment