Learn Git Within 5 Minutes

Track the changes and collaborate easily. 😄😄

Rohan Shakya
2 min readJul 30, 2020
Photo by Richy Great on Unsplash

What is Git?

Git is a distributed version control system (DVCS), also known as decentralized. Git was initially designed and developed by Linus Torvalds for Linus Kernel development. Git is free software distributed under the terms of the GNU General Public License version 2.

Advantages of Git

  • Free
  • Open Source
  • Security
  • Backup
  • Branching

Every developer has a full copy of the repository which is hosted in the cloud.

Download and install Git

Linus:

sudo apt-get update

sudo apt-get install git

Windows:

Download from the official page.

Create a repository

  • Create a new repository also known as a repo.

git init [project_name]

  • Clone an existing repository.

git clone [url]

Make a change

  • Stages the file, ready for commit

git add <file>

  • Add all current changes to the next commit

git add .

  • Check for the status

git status

  • Commit all stages files to versioned history

git commit -m “commit message”

  • Unstaged file, keeping the file changes

git reset - -hard

Working with branches

  • List all existing branches

git branch

  • Switch HEAD branch

git checkout <branch>

  • Create a new branch called new_branch

git branch new_branch

  • Tag the current commit

git tag new_tag

Merge & Rebase

Merge <branch> into your current HEAD

git merge <branch>

  • Rebase your HEAD onto <branch>

git rebase <branch>

  • Continue a rebase after resolving conflicts

git rebase - -continue

Update & Publish

  • List all currently configured remotes

git remote -v

  • Download all changes from <remote>

git fetch <branch>

  • Public local changes on a remote

git push <remote> <branch>

Undo

  • Discard all local changes in your directory

git fetch <branch>

  • Discard local changes in a specific file

git checkout HEAD <file>

  • Reset your HEAD pointer to the previous commit

git reset - -hard <commit>

You are also recommended to look at some of these for more information:

I have shown you what works for me! But check out these for more information.

https://www.tutorialspoint.com/git/

— An excellent introductory tutorial

https://www.codecademy.com/learn/learn-git

— Another excellent introductory tutorial

https://git-scm.com/docs/gittutorial

— A fairly long overview tutorial

http://www.vogella.com/tutorials/Git/article.html

— A fairly long detailed tutorial

Thank You !! 😊

--

--