Because my shell history will not remember all those commands forever I dump some of my favorites here. Over time I surely will add more...
Last updated on
git reset the index and working tree. Any changes to tracked files in the working tree since
<commit> are discarded.
git reset --hard HEAD
Or revert latest local commit:
git reset HEAD~1
With git push you can update a remote repository.
The command falls back to "the current branch is pushed to the corresponding upstream branch", if no special configurations or options are present.
Delete remote branch
A highly voted question How do I delete a Git branch locally and remotely?
$ git push origin --delete my-feature-branch - [deleted] my-feature-branch
$ git branch --delete --remotes origin/my-feature-branch Deleted remote-tracking branch origin/my-feature-branch (was abcdefg).
Either way the local branch still exists. You can check the status with:
$ git branch --no-color -v main abcdefg Add fancy feature * my-feature-branch 0123456 [gone] Add my feature
Hint: Deleting the local branch will keep you posted in case you haven't merged already.
$ git branch --delete my-feature-branch warning: deleting branch 'my-feature-branch' that has been merged to 'refs/remotes/origin/my-feature-branch', but not yet merged to HEAD. Deleted branch my-feature-branch (was 0123456).
Make an unsigned, annotated git tag object, delete and list tag objects.
git tag -a -m "Release 0.1.8" release_0_1_8 git tag -a -m "Release 0.1.8" v0.1.8 git tag -d release_0_1_8 git tag -l
How to show the currently used git remote:
$ git remote origin $ git remote -v origin git://git.eclipse.org/gitroot/virgo/org.eclipse.virgo.kernel.git (fetch) origin git://git.eclipse.org/gitroot/virgo/org.eclipse.virgo.kernel.git (push)
Git clone and checkout a single branch:
git clone -b docs --single-branch git://git.eclipse.org/gitroot/virgo/org.eclipse.virgo.kernel.git
With git fetch you can fetch branches and tags.
- Fetch from all remotes
- Prune tracking branches, if they are no longer present on remote(s)
git fetch --all --prune
Also discussed on Stack Overflow:
- How to fetch all git branches
- How to prune local tracking branches that do not exist on remote anymore
Working with Git submodules...
The following sequence shows how to create (and checkout) all submodules recursively with foreach:
git submodule foreach git branch 3.7.0.M02 git submodule foreach git checkout 3.7.0.M02
git submodule update --remote --merge
Get the short commit hash:
git rev-parse --short HEAD
To be continued...