In this post I will share a collection of Git useful commands that I’m certain we will need during our daily work as a developer. I will keep updating this list as I come across other operations.
Please use some of these commands with caution, as they may lead you to data loss if don’t know exactly what you’re doing.
git init
git clone <repo_url>
git pull
You might need this when you just created a new repo on the remote server and then initialised it with a file, but you also initialised a git repo locally. That means that the master
branch on the remote repo started differently from the master
branch locally, hence, they are unrelated.
git pull --allow-unrelated-histories
git push
git push -u <remote_name>
git checkout <branch>
git checkout -b <branch>
git checkout tags/<tag_name>
git branch
git branch -r
git branch -a
git remote show origin
The following merges the changes from master into a custom my-feature-branch
:
git checkout my-feature-branch git merge master
A stash is a separate working directory used to keep the changes you’d like to get rid for now. Useful for when you decide not to include a specific change as part of the commit, but need it later for another set of changes.
git stash
git stash show -p
git stash show -p <stash_reference>
git stash clear .
git reset HEAD~
For example, the commit id aed94874
will be removed from the branch master
git push origin +aed94874^:master
You will lose your changes.
git reset --hard git clean -fd
I personally always create aliases for the following set of commands in my operational system.
git checkout master && git pull && git fetch --tags && git remote prune origin && git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
git config user.name "bgasparotto" git config user.email "bruno.m.gasparotto@gmail.com"
This guide will show you how to create a Python function decorator with a few…
This guide will show you how to fix the error Got permission denied while trying…
This guide will show you how to create a Python virtual environment on Intellij IDEA…
This tutorial will quickly show you how to to find and kill processes on Linux,…
This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…
I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…