A simple guide to start with GIT

Set up git :

Create a new repository locally

git init

Create a Local Copy of a Git repository

git clone path/to/remote/repo

Add a remote

git remote add <remote> <remote_url>
git remote -v

GIT 3 tree Architecture

  1. working directory — holds the actual files
  2. Index or Staging — the place where files get prepared to be packaged into a commit object
  3. HEAD — points to the last commit that is done
3 Tree Architecture

Stage Changes

git add <file_tobe_added>git add *
git status
git rm --cached <file_tobe_removed>

Commit Changes

git commit -m “The commit message for the changes"
git reset --soft HEAD^
git commit --amend -m "The modified commit message"
git log

Push changes

git push origin master
git remote add origin <server>

Working with branches

GIT Branch
git checkout -b <new_branch_name>
git checkout <branch_tobe_checkout>
git branch -d <branch_tobe_deleted>
git push origin <branch>

Update and merge the changes

git pull <remote_name> <branch_tobe_pull>
git merge <other_branch>
git diff <source> <target>

Git Tags

git tag <tag_name> <commit_id>
git tag
git checkout <tag_you_want>

git squash

git rebase -i HEAD~3

git cherry-pick

git cherry-pick <commit-hash>
git cherry-pick -x <commit-hash>

git stash

git stash
git stash pop

Cheat Sheet

git init = create a local repository
git clone /path/to/remote/repository = Create a local copy
git remote add <remote_name> <remote_url> = add a remote repository
git remote -v = see all the remote repositories added
git add <file_tobe_added> = add one file to the staging
git add * = add all the changes to the staging
git status = explore the staging
git rm --cached <file_tobe_removed> = remove a file from the staging
git commit -m “Commit message” = commit changes
git reset --soft HEAD^ = undo the last commit
git commit --amend -m “Modified Commit message” = modify a commit
git checkout <filename> = replace local changes
git log = view all the commits
git push origin master = push changes to the remote server
git checkout -b <branch> =Create a new branch and checkout
git checkout <branch> = Switch to a branch
git branch -d <branch> = delete a branch
git pull <remote_name> <branch> = get changes of the remote
git merge <branch> = merge a branch to the current branch
git diff <source> <target> = preview the differences
git tag <tag_name> <commit_id> = create a tag from a commit-hash
git tag = view all the tags
git checkout <tag_you_want> = checkout a specific tag
git rebase -i HEAD~3 = squash the last 3 commits
git cherry-pick <commit-hash> = get commit from a branch to another
git cherry-pick -x <commit-hash> = cherry-pick from a public branch,
git stash = save the current modifications temporary
git stash pop = drop the temporarily saved changes




Senior Software Engineer @ WSO2 focused on the IAM domain

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create a Dashboard with Flask, Plotly, Altair, Chart.js, and AdminLTE

Create Unique Websites with Custom Tailwind CSS Fonts

Props Circulating Supply Explained — in preparation for upcoming exchange listings

I never knew it’s significance until today!

Software Testing — a sketch

Resolving the wasm-pack error: ‘locals exceed maximum’

C# — Intro

ASP.NET Core In Action

Android + OpenCV: Part 5 — JNI Implement Test: getMessage() and askQuestions()

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pamoda Wimalasiri

Pamoda Wimalasiri

Senior Software Engineer @ WSO2 focused on the IAM domain

More from Medium

Introduction to Type systems

Go nulls and SQL

RESTful API — What You Need To Know

Creating Orphan branches in Git