Git Cheatsheet

Basic Git Commands

Do something

git something

Branches

List local branches

git branch

List all branches

git branch -av

Create a branch

git branch <branch_name>

checkout Create a branch

git checkout <branch_name>

Create and checkout a branch

git checkout -b <branch_name>

Delete local branch

git branch -d <branch_name>

Force delete local branch

git branch -D <branch_name>

Delete a remote branch

git push <remote_name> --delete <branch_name> or git push <remote_name> :<branch_name>

Tagging

git provides 2 types of tags: * lightweight * annotated

Note
Tags are not pushed by default. You have to either push them explicitly or push them all git push <remote> --tags

List tags

git tags

Search for specific tags

git tag -l "v1.8.5*"

Useful aliases and tips

If you use dev, test, prod style tags e.g. three-tier-app-prod-1.23 then sort’s `--version-sort is useful.

e.g.

function gt { git tag -l "${1}*${2:-prod}*" | sort --version-sort }

Setting up linters

Ignore or deactivate a linter git commit -an or --no-verify

Resources

Tony Kay avatar
About Tony Kay
Team lead for Automation and Management in Red Hat's GPTE DevOps and Automation team. Working globally, I focus primarily on Hybrid Cloud Automation with Ansible. About 2/3rds of my time is automating production cloud deployments and developing both code and training content. I also deliver Automation training globally to both Red Hat and Partner Consultants and Architects on cloud infrastructure using Ansible and on OpenShift/Kubernetes.
comments powered by Disqus