Introduction to Git and Git Hosting Platforms
π§ What is Git?
Git is a distributed version control system used to track changes in source code during software development.
It allows multiple developers to collaborate efficiently.
- Tracks file changes over time
- Allows branching and merging
- Works locally without internet
π What is GitHub?
GitHub is a cloud-based platform that hosts Git repositories. It helps developers share code, collaborate, and manage projects.
- Hosts remote Git repositories
- Offers pull requests, issues, and actions
- Popular among open-source communities
π οΈ Other Git Hosting Platforms
- GitLab: A Git-based DevOps platform that includes CI/CD, issue tracking, and project planning tools.
- Bitbucket: A Git repository management tool from Atlassian with Jira integration and support for private repositories.
- SourceForge: A web-based service that offers version control, bug tracking, and downloads for open-source projects.
- Azure Repos: Microsoft's Git hosting platform with enterprise-grade DevOps integration.
π Common Git Workflow in a Project
The following sequence of Git commands is commonly followed throughout the lifecycle of a project:
git clone <url>
: Clone an existing repository to start working on a project
git checkout -b feature-name
: Create and switch to a new feature branch
git add .
: Stage changes after editing or adding files
git commit -m "Describe the change"
: Commit staged changes with a meaningful message
git pull origin main
: Pull latest changes from the main branch before pushing
git push origin feature-name
: Push the branch to the remote repository
- Create a pull request on the hosting platform (e.g., GitHub)
- Get code reviewed and merged into the main branch
git checkout main
& git pull
: Switch back to main and pull latest updates
git branch -d feature-name
: Delete the local branch once itβs merged
π₯οΈ Working with Git in VS Code
Visual Studio Code provides a user-friendly UI to work with Git. Here's how to use it:
- Open your project folder in VS Code
- Click the Source Control icon (
Ctrl+Shift+G
or π§ icon in sidebar)
- Stage changes using the + button next to modified files
- Add a commit message and click the βοΈ checkmark to commit
- Use the three-dot menu (...) to pull, push, or view branches
- Switch or create branches from the status bar (bottom left corner)
- View Git logs, diffs, and resolve merge conflicts with built-in UI
- Use the integrated terminal for advanced Git commands
- Install extensions like GitLens for enhanced Git capabilities
VS Code also integrates well with GitHub via the GitHub Pull Requests Extension.
β
Why Use Git & Git Hosting Platforms?
- Track every change and revert if needed
- Collaborate with others easily
- Work on different features using branches
- Keep your code safe and accessible in the cloud
- Enable CI/CD pipelines for automated testing and deployment