PUBLISHED: October 18, 2019
Deprecation Notice: This article was written more than a year ago which means that its information might no longer be
up-to-date. We cannot therefore guarantee the accuracy of it's contents.
Amend commit message. Useful if you, for example, want to change your latest comment but do want to make another commit.
Update list of remote branches and from your local repository, remove those that not longer exist remotely.
If you work in a large team the list of branches usually grows over time.
If you do not tell Git to perform some house cleaning every now and then, your local repository list will soon be
cluttered with many obsolete branches.
Print list of local branches and also include any remote branches that have not yet been checkout out.
Reset current branch to remote HEAD. Very useful if you want restore your local branch to its initial (remote) state.
Always make sure that your remote list is up-to-date by issuing the
Force delete local branch. A less aggressive
Delete remote branch. Use with care. Only run this command when you are absolutely certain that the remote branch is no
longer required.
Rename local branch. This command renames the current branch, so do ensure that you are working on the correct branch.
Rebase the latest number of commits. This is useful if you, for example, want to squash multiple commits into one
single commit before merging the changes back to the master branch. When the rebase dialog pops up,
it is recommended to pick (p) the first commit and squash (s) every subsequent commit.
Store un-committed changes in a temporary “buffer”. Useful if you, for example, want to checkout another branch or
pull the latest remote branch without having to commit your local changes. Once the changes have been stashed your
branch will appear “clean”.
Restore changes from the temporary “buffer” onto the current branch.
The stash acts on a First In First Out (FIFO) basis, so if you have multiple stashes,
the latest one will always be applied first.
Table of Contents
10 Useful Git Commands
Here at GeekBitZone we use extensively Git as our version control system. As a matter of fact, even our statically generated website is under Git’s version control. Below are ten useful commands that we use on a daily basis.
git commit —amend
$ git commit —amend
git fetch —prune
$ git fetch —prune
git branch -vv
$ git branch -vv
git reset —hard origin/<branch>
$ git reset —hard origin/mybranch
git fetch origin
command first.
git branch -D <branch>
$ git branch -D mybranch
git branch -d <branch>
command can also be used,
provided that there are no un-merged changes left in the branch.
git push —delete origin <branch>
$ git push —delete origin mybranch
git branch -m <name>
$ git branch -m mynewname
git rebase -i HEAD~<n>
$ git rebase -i HEAD~3
git stash
$ git stash
git stash pop
$ git stash pop
Summary
These are GeekBitZone’s ten favourite Git commands. Which ones do You use on a daily basis?
Do let us know by posting your comments below.
See Also
How to access a Plex Server behind CGNAT with ngrok
10 Influential Pixel Artists
How to Customise the Linux Bash Prompt
How to Merge and Rebase in Git
How to add new PDF compression filters for the Preview tool on Mac
How to create PDFs with the Preview tool on Mac
How to install Homebrew for Mac
How to find out which shell I am running?
How to sync files with lftp
How to mirror drives with rsync
comments powered by Disqus
See also
- How to access a Plex Server behind CGNAT with ngrok
- 10 Influential Pixel Artists
- How to Customise the Linux Bash Prompt
- How to Merge and Rebase in Git
- How to add new PDF compression filters for the Preview tool on Mac
- How to create PDFs with the Preview tool on Mac
- How to install Homebrew for Mac
- How to find out which shell I am running?
- How to sync files with lftp
- How to mirror drives with rsync