- Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
- It tracks changes to files, allowing multiple people to work on them simultaneously, coordinating their work seamlessly.
- Linux: Install via package manager (
apt,yum, etc.).sudo apt-get install git # Debian/Ubuntu sudo yum install git # CentOS/Fedora
- Mac: Install Git using Homebrew or download from the Git website.
brew install git # Homebrew - Windows: Download and install from Git for Windows.
- Set your username and email address:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com" git --version # To confirm that git is installed and configured correctly on your machine
- Initialize a new Git repository:
git init
-
Checking Status:
git status
-
Adding Files:
git add <filename> # Stage specific file git add . # Stage all files
-
Committing Changes:
git commit -m "Commit message"
-
Creating a Branch:
git branch <branch-name> git checkout <branch-name> # Switch to the new branch
-
Merging Branches:
git checkout main # Switch to main branch (or target branch) git merge <branch-name> # Merge changes from <branch-name> into main
-
Linking to a Remote Repository:
git remote add origin <remote-url> # Add a remote repository
-
Pushing Changes:
git push -u origin main # Push local changes to the remote repository -
Pulling Changes:
git pull origin main # Pull latest changes from remote repository
- Conflict Resolution:
- Edit conflicted files to resolve conflicts.
- Add resolved files using
git addand commit changes.
- Viewing Commit History:
git log # View commit history git log --oneline # Compact view of commit history
-
Undoing Changes:
git reset HEAD <filename> # Unstage changes git checkout -- <filename> # Discard changes in working directory
-
Git Help:
git --help # Git command help
- Official Git Documentation: Git SCM
- GitHub Guides: GitHub Docs
- Interactive Learning: Git - Learn