Git Notes

Collection of commands that are useful when using git, but I always seem to forget.

Update Branch

Update your branch appending your (not yet merged) commits on top of the changes.

1
2
git fetch
git rebase <remote>/<branch>

Remove Remote Branch

First remove the branch locally, then remotely.

1
2
git branch -d <branch> # -D to force remove.
git push <remote> --delete <branch>

List commits added in different branch

List all commits in other_branch not in the master branch.

1
git log HEAD..other_branch

Also show the actual changes.

1
git log --patch HEAD..other_branch

Last Commit

Last commit.

1
2
git log -1 HEAD
git log -1 HEAD --patch # With changes.

Only the commit hash.

1
git rev-parse HEAD

Cleaup

Reduce disk space by packing objects.

1
git gc --aggressive