Version Control For Git and Github
Version Control For Git and Github
What is Git?
Git is a distributed version control system that allows multiple developers to
collaborate on a project while keeping track of changes.
What is GitHub?
GitHub is a cloud-based hosting service for Git repositories that facilitates
collaboration, version control, and project management.
2. **Track Changes**:
To track a file or folder, use `git add`:
```bash
git add <filename>
```
3. **Commit Changes**:
Commit the changes you made:
```bash
git commit -m "Your commit message"
```
4. **Push to GitHub**:
Push your local repository to GitHub:
```bash
git push origin main
```
Branching:
- Branches are used to work on separate features without affecting the main
codebase.
- To create a new branch:
```bash
git checkout -b feature-branch
```
- To switch between branches:
```bash
git checkout main
```
Merging:
- Merge changes from one branch to another:
```bash
git merge feature-branch
```
GitHub Workflow:
1. Fork a repository to create your copy of a project.
2. Clone it to your local machine:
```bash
git clone <repo-url>
```
3. After making changes, push them to GitHub:
```bash
git push origin main
```
4. Submit a pull request for your changes to be reviewed.
Best Practices:
- Write clear commit messages that explain what was changed and why.
- Regularly push your changes to the remote repository to avoid conflicts.
- Use branches for new features and bug fixes, keeping `main` stable.
Conclusion:
Git and GitHub are essential tools for version control and collaboration in modern
software development. Knowing how to use them efficiently will make your workflow
smoother and more productive.