Git Cheat Sheet for Developers

Β·

2 min read

Hello Friends,

Many times in our development career, we have to use git to manage our personal project repositories or company's project. We cannot run away from git. So here I am presenting you ultimate git cheat sheet for your reference.

Let's start it without wasting in further time.

GIT BASICS

git init <directory>

Create empty git repository in specified directory. Run with no argument to initialize the current directory
as a git repository.

git clone <repo>

Clone repo located at onto local machine.

git config user.name <name>

Define user name for all commits in the current repo. Devs commonly use --global to set config options for current user.

git add <file>

Used to add to staging area for commit. You can user git add . to add all changed files to staging area.

git commit -m <message>

Commit all staged files. must be relevant to what you are commiting.

git status

List all staged, unstaged, untracked files.

git log

Display the entire commit history in the default format.

git diff

Shows unstaged changes between your local and remote repository.

GIT BRANCHES

git branch

Lists all the branch in your repo. Add to add new branch to your repo with name .

git checkout -b <branch>

Create and checkout a new branch named . Remove -b to checkout an existing branch.

git merge <branch>

Merge branch into the current branch.

REMOTE REPOSITORIES

git remote add <name> <url>

Create a new connection to a remote repo. After adding remote you can use as a shortcut for in other commands.

git fetch <branch>

Fetches a specific branch from the repo. Remove to fetch all remote branches.

git pull

Fetch the remote's copy of current branch. Immediately merge it into your local copy.

git push

Pushes all commits to your repo.

GIT RESET

git reset

Reset staging area to match most recent commit, but leave the current directory unchanged.

git reset --hard

Reset staging area and working directory to most recent commit and overwrites all changes in the working directory.

Β