Introduction to git

Contents

  1. What is git?
  2. Basics - Initialising, staging, committing 
  3. Branching
  4. Collaboration
  5. Why is git so useful?
  6. Links for further reading

What is git?

  • A distributed version control system
  • Developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel
  • Prompted by breakdown in relationship between the Linux community and the company that provided BitKeeper - the VCS they used to use.

Basics

Demo

  • VS Code is an editor with great git integration.
  • Let's use VS Code to understand some basic git workflows.
git init

git init creates a .git folder

git add <filename> (or * for everything)
git commit -m "Commit message"
git status
git diff <filename>

And again...

git log

Branching

git checkout -b feature_x
git log

Branches are used to develop features isolated from each other.

git merge <branch>
git log

This is what the graph looks like after the merge.

Collaboration

Setting up a remote

  • A remote repository could be one on a web-based hosting service like Github or Azure DevOps.
  • Or, it could be on your Local Area Network.
  • By having a remote repository that everyone can push their changes to, multiple developers can work on the same project simultaneously!

Example Github repo

git remote add origin <server>
git push origin master
git log

Why is git so useful?

  • No need to worry about losing your code when making changes because you can easily revert it.
  • Easily see what changes were made in a commit.
  • Collaborate with other developers.

 

And lots more...

Relevant links

Introduction to git

By Vipin Ajayakumar

Introduction to git

  • 682