My List of Commonly-Used Git Commands

One of the tools I use on a daily basis is Git, a Distributed Version Control System (DVCS). Other than the usual git checkout -b branch, git tag -a and git merge/push/pull, the Git workflow generally demands very little of me to keep the repository under control.

If not for a few “human errors” that happen once in a while (or a couple of times every week), there’s not much to write home about. In those instances, I have to admit that relying on the search engine to answer specific questions usually gets things done faster than parsing the man/help page or going through the docs. Lazy. I know!

After repeating the same process a few times and finding answers on different sites, I decided to just compile a list as I go along rather than trying to remember the search terms I used to get the answer last time. In any case, here is the list of my commonly-used as well as “almost” commonly-used Git commands.

Branching with Git

:::bash
#list all branches
git branch -l

# create and immediately checkout a new branch
git checkout -b [branchname]

# create a new branch
git branch [branchname]

# delete branch
git branch -d [branchname]

# all local branches up to remote repository
git push [remotename] --all

# delete remote branch
git push [remotename] :[branch name]

# track a remote repository
git branch --track [branchname] origin/[branchname] 

Tagging with Git

:::bash
# list all available tags
git tag -l

# create an annotated tag
git tag -a [tagname]

# delete tag
git tag -d [tagname]

# remove remote tag
git push [remotename] :refs/tags/[tagname]

# push all local tags to remote
git push [remotename] --tags

# fetch all remote tags
git fetch --tags

# show verbose view of the tag
git show [tagname]

Remote Repository Management with Git

:::bash
# view existing remote urls
git remote -v

# change origin remote's URL
git remote set-url origin [path to new repository]

# add remote
git remote add [remote-name] [path to remote repository]

# pull changes from remote
get fetch [remote-name]

Other Commonly-used git Commands

:::bash
# merge codes with another branch
git merge [branchname]

# neater way to view git log that I actually created an alias called "git_pretty"
git log --pretty=oneline --max-count=[no. of lines] --abbrev-commit

I plan to update this list every time I have to search for the same thing twice! So what are some of your commonly used git commands?

Contents

  1. 1. Branching with Git
  2. 2. Tagging with Git
  3. 3. Remote Repository Management with Git
  4. 4. Other Commonly-used git Commands