- Git is a distributed version control system (DVCS) that tracks changes in files and enables collaboration.
- Key Features:
- Maintains a history of file changes.
- Allows reverting to previous states.
- Enables branching and merging.
- Example Alternatives: Mercurial, Bazaar, Darcs.
- A cloud platform for hosting Git repositories and enabling collaboration.
- Functions:
- Centralized repository for teams.
- Simplifies code merging and version control across the globe.
- Difference:
- Git: Local version control.
- GitHub: Global collaboration platform using Git.
- Download from git-scm.com and install.
- Verify installation:
git --version
- GitHub Desktop: GUI tool for managing repositories.
- Setup Steps:
- Download from desktop.github.com.
- Configure using your GitHub account.
- Initialize Git:
git init
- Configure username and email:
git config --global user.name "Your Name" git config --global user.email "youremail@example.com"
- Verify configuration:
git config --list
- Working Directory: Local files you're editing.
- Staging Area: Prepares changes for the next commit.
- Local Repository: Stores committed changes on your machine.
- Remote Repository: Centralized repository (e.g., GitHub).
- Initialize a Repository:
git init
- Add Files to Staging Area:
git add filename git add . # Adds all changes
- Commit Changes:
git commit -m "Commit message" - Push to Remote:
git remote add origin <repository_url> git branch -M main git push -u origin main
- Pull Changes:
git pull origin main
- Create a branch:
git branch branch_name
- Switch to a branch:
git checkout branch_name
- Merge branches:
git merge branch_name
- Use a code editor to resolve conflicts.
- Add changes after resolving:
git add . - Commit the resolution:
git commit -m "Resolved merge conflict"
- Use meaningful commit messages:
git commit -m "Fix: Resolved bug in login logic" - Keep your repository organized with clear branching strategies.
- Regularly pull changes from the remote repository to stay updated.
- Version Control Systems Comparison:
- Centralized: Subversion.
- Distributed: Git, Mercurial.
- Understanding .gitignore:
- List files/folders to exclude from tracking.
- Licenses in Repositories:
- Use ChooseALicense.com to decide.