Git Basic Syntax Notes
- KeLin Cheng
- Tutorial
- September 1, 2024
Table of Contents
Basic Git workflow for beginners.
1. Install Git
Download from https://git-scm.com/. Verify: git --version
2. Configure Git
git config --global user.name 'Your Name'
git config --global user.email 'your_email@example.com'
3. Create Repository
mkdir my_project
cd my_project
git init
4. Stage Files
git add README.md # Add specific file
git add . # Add all files
5. Commit Changes
git commit -m 'Initial commit'
6. Check Status & History
git status # Working tree status
git log # Commit history
7. Branch Operations
git branch feature-branch # Create branch
git checkout feature-branch # Switch branch
git checkout -b feature-branch # Create and switch
8. Merge Branches
git checkout main
git merge feature-branch
9. Remote Repository
git remote add origin <repository-url>
git push -u origin main
git pull origin main
10. Clone Repository
git clone <repository-url>
References
- Git Official Documentation. https://git-scm.com/doc
- Chacon, S. & Straub, B. (2014). Pro Git (2nd ed.). Apress. https://git-scm.com/book/en/v2
Practice Exercises
- Create a new branch, make three commits on different files, then use
git rebase -ito squash them into a single commit. What happens to the commit history, and why might you want to use rebase vs. merge? - Simulate a merge conflict: have two branches modify the same line of the same file, then practice resolving the conflict manually. What strategies does Git provide to help with conflict resolution?