Version Control System Setup and Basics
Git is a version control system that helps developers track changes in their code over time. It allows multiple people to work on the same project without overwriting each other's work.
Think of Git as a "time machine" for your code - you can go back to any previous version whenever you want!
GitHub is a platform that hosts Git repositories online. It's like "Google Drive for code" where you can:
Visit git-scm.com/downloads and download Git for your operating system.
Run the installer and follow the setup wizard. Use the default options for most settings.
Open your terminal/command prompt and type:
git --version
You should see the Git version number if installation was successful.
After installing Git, you need to set up your identity:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Replace "Your Name" and "your.email@example.com" with your actual name and email address.
To check your configuration:
git config --list
Navigate to your project folder and run:
git init
This creates a new Git repository in your folder.
See which files have changed:
git status
Stage files for the next commit:
git add filename.txt # Add specific file
git add . # Add all files
Save your changes with a message:
git commit -m "Your commit message"
See your commit history:
git log
Visit github.com and sign up for a free account.
Click the "+" icon in the top right and select "New repository". Give it a name and description.
After creating a repository on GitHub, you'll see commands to connect your local repository:
git remote add origin https://github.com/yourusername/your-repo-name.git
git branch -M main
git push -u origin main
# 1. Create or navigate to your project folder
cd my-project
# 2. Initialize Git repository
git init
# 3. Create a new file
echo "# My Project" > README.md
# 4. Check status
git status
# 5. Add files to staging
git add .
# 6. Commit changes
git commit -m "Initial commit"
# 7. Connect to GitHub (only once)
git remote add origin https://github.com/yourusername/my-project.git
# 8. Push to GitHub
git push -u origin main
| Issue | Solution |
|---|---|
| "git is not recognized" | Git is not installed or not in PATH. Reinstall Git. |
| Authentication failed | Use personal access token instead of password for GitHub. |
| Permission denied | Check if you have write access to the repository. |
| Merge conflicts | Manually resolve conflicts in the files, then commit. |