Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 1 of 10

Version Control with Git & GitHub

Git is the industry-standard version control system. Every developer job requires Git. It tracks code changes, enables collaboration, and provides a safety net - you can always revert to a previous version.

15 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Git Essentials

  • git init - Initialize a repository in your project folder
  • git add . - Stage all changes for commit
  • git commit -m 'message' - Save staged changes with a description
  • git push - Upload commits to remote (GitHub, GitLab)
  • git pull - Download latest changes from remote
  • git branch / git checkout - Create and switch branches for features
  • .gitignore - List files to exclude: node_modules/, .env, dist/
  • Pull Request (PR) - Propose changes for review before merging to main branch

Git Workflow Code

Git Workflow Code
// Essential Git commands

// Setup (one time)
// git init                          // start tracking
// git remote add origin <url>       // connect to GitHub

// Daily workflow
// git status                        // what changed?
// git add .                         // stage all changes
// git commit -m "Add login feature" // save snapshot
// git push origin main              // upload to GitHub

// Branching (feature development)
// git branch feature/login          // create branch
// git checkout feature/login        // switch to branch
// git checkout -b feature/signup    // create AND switch

// After feature is done:
// git checkout main                 // switch to main
// git merge feature/login           // merge feature in
// git push origin main              // upload

// Undo mistakes
// git revert HEAD                   // undo last commit (safe)
// git stash                         // temporarily save changes
// git stash pop                     // restore saved changes
// git log --oneline -5              // view last 5 commits

// .gitignore file
// node_modules/
// .env
// dist/
// .DS_Store
// *.log

console.log("Git commands for daily development workflow");
console.log("Learn git: https://learngitbranching.js.org");

Tip

Tip

Write descriptive commit messages: 'fix: resolve login redirect loop on expired tokens' is much better than 'fix bug'. Use conventional commits (feat:, fix:, docs:, refactor:) for a clean, searchable history.

Diagram
Loading diagram…

Version Control with Git & GitHub in JavaScript

Common Mistake

Warning

Committing directly to main/master branch. Always create a feature branch, make changes there, then submit a pull request. This prevents broken code from reaching production and enables code review.

Practice Task

Note

Git workflow: (1) Initialize a repo, create a branch, make 3 commits with good messages. (2) Merge the branch back. (3) Practice resolving a merge conflict. (4) Use git log --oneline to review history.

Quick Quiz

Key Takeaways

  • Git is the industry-standard version control system.
  • git init - Initialize a repository in your project folder
  • git add . - Stage all changes for commit
  • git commit -m 'message' - Save staged changes with a description

Finished this lesson?

0 of 10 in Module 12
Sign in to save progress

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done