Welcome to the world of Git, a powerful version control system that helps you manage and track changes in your projects. Whether you're a coding novice or a seasoned developer, understanding Git is crucial for efficient collaboration and project management.
Chapter 1: Getting Started (Basics)
1. Repository
Git is all about repositories - digital project folders. To create a new one, use:
git init
To grab an existing one from the web:
git clone <repository-url>
2. Clone
Clone is like making a copy of a project. Use it to snag a remote repository:
git clone https://github.com/example/repo.git
3. Commit
Think of commits as snapshots of your project. To save your changes:
git add <filename>
git commit -m "Your commit message here"
4. Push
Push is for sharing your local changes with others:
git push origin master
5. Pull
Pull is for grabbing changes others made:
git pull origin master
6. Branch
Branches let you work on different parts at the same time:
git branch <branch-name>
git checkout <branch-name>
7. Merge
Merge combines changes from one branch into another:
git checkout master
git merge <branch-name>
8. Remote
Remote is the centralized repository where everyone collaborates:
git remote add origin <repository-url>
9. Fetch
Fetch gets changes from the remote without merging:
git fetch origin
10. HEAD
HEAD points to the latest commit in your working branch:
git log
Chapter 2: Advanced Techniques
1. Rebasing
Rebasing helps tidy up your commit history:
git checkout feature-branch
git rebase master
2. Stash
Stash is for saving changes not ready to be committed:
git stash
3. Cherry-picking
Cherry-picking lets you apply specific commits:
git cherry-pick <commit-hash>
4. Submodules
Submodules include external projects in your repository:
git submodule add <repository-url> <path>
5. Hooks
Hooks are scripts that run at key Git points:
Create pre-commit
in .git/hooks/
with your script.
6. Gitignore
.gitignore excludes files from version control:
touch .gitignore
Edit to specify files to ignore.
7. Reflog
Reflog logs all changes to your repository:
git reflog
8. Bisect
Bisect helps find when a bug was introduced:
git bisect start
git bisect bad
git bisect good <commit-hash>
9. Tagging
Tags mark specific points in history:
git tag -a v1.0 -m "Version 1.0"
10. Interactive Rebase
Interactive rebase lets you modify commits:
git rebase -i HEAD~3
Mastering these basics and advanced Git concepts will empower you to efficiently manage your projects and collaborate seamlessly. Feel free to reach out if you want more details or explanations on any concept. Happy coding!
Top comments (0)