Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics & Commands

Updated
2 min readView as Markdown

Short answer: Git is a version control system (a tracker) that tracks changes in our code base.

What is git?

git helps us track changes in our project such as code modifications, newly added files and the user who has made these changes.

Why git is used?

Well, git is used to avoid the hassle of tracking these code changes, saving history and helps in collaboration.

  • work/changes are saved as commits, we can move back and forth among these commits.

  • Branching makes experimentation easier as multiple developers can work simultaneously.

Common concepts

  • repository : a storage of our code, local (our machine) or remote ( github).

  • commits : commits is how we track these changes and save them.

  • branch : branches can help us work on new tests/experiments on code easily.

    for example- these provide us a snapshot of the current state/ or main branch of repository and now experimentation can be continued in this new branch, if all goes well we can merge these changes back.

Developer workflow

  • git init - initialize git in repo

  • git branch -m “branch-name” - changes the current branch name, git branch -m main

  • git add <file> - add file to staging area

    • git add . - stage all changes
  • git status - status of files can be seen added or not in staging area

  • git commit -m "your_msg" - commit / save these files with a message about the changes.

commands-

  • git log - a log of previous commits/history

  • git branch - check branch

  • git switch -c “new-branch-name” - new branch

  • git branch -D “branch-name” - delete a branch

  • git diff / git diff <latest-commit-hash> <prev-commit-hash