Git is the most popular version control system, widely used for tracking changes in source code during software development.
A Git repository is a hidden subfolder within your project directory that contains all of your project files and the entire revision history.
Git files can reside in one of three states: modified, staged, and committed.
Git allows you to create branches, enabling you to work on different features or
fixes without affecting the main
branch. This facilitates parallel development
by multiple developers.
Git merge combines two separate development histories into one. For
instance, you can merge changes from a feature branch into the main
branch to
integrate new features or bug fixes.
Set your Git username:
git config --global user.name "Your GitHub Username"
Set your Git email:
git config --global user.email "your.email@example.com"
Set VS Code as the default editor:
git config --global core.editor "code --wait"
Handle end-of-line configurations:
For macOS or Linux:
git config --global core.autocrlf input
For Windows:
git config --global core.autocrlf true
View all global configurations in VS Code:
git config --global -e
Initialize an empty Git repository:
git init
List all untracked files:
git status
Add a file to the staging area:
git add <file-name>
Add all files to the staging area:
git add .
Remove a file from the staging area:
git reset <file-name>
Commit changes with a descriptive message:
git commit -m "Descriptive message"
Save changes temporarily without committing them:
git stash
Restore stashed changes:
git stash apply
Create a new branch:
git branch <branch-name>
Switch to a new branch:
git checkout <branch-name>
Create a new branch and switch to it:
git checkout -b <branch-name>
Revert a commit:
git revert <commit-hash>
Reset changes:
git reset
Display the most recent commits:
git log
Compare changes between commits:
git diff
Integrate changes from one branch onto another:
git rebase <branch-name>