- Definition: GitHub is a web-based platform that uses Git, a distributed version control system, for tracking changes in source code during software development.
- Importance: Essential for collaboration, allowing multiple people to work on a project simultaneously. Widely used in open-source projects and professional development.
- Version Control System (VCS): Tracks changes, allows reverting to previous states, and manages modifications by multiple people.
- Repositories:
- Local Repository: On your computer, where changes are made.
- Remote Repository: Stored on GitHub's server for sharing and collaborating.
- Commits: Records of changes to the repository, each with a unique ID.
- Branches: Different versions of the repository. Main branch is usually
mainormaster. - Merges: Combining changes from different branches.
- Pull Requests: Requests for someone to review and pull in your contribution.
- Forks and Clones:
- Fork: A GitHub copy of a repository for making changes without affecting the original.
- Clone: Copying the repository to your local machine.
- Windows: Download and install from Git's website.
- Mac: Use Homebrew (
brew install git) or Git's website. - Linux: Install via the distribution's package manager (e.g.,
sudo apt-get install gitfor Ubuntu).
- Sign up on GitHub's website.
- Fill in details and verify the account.
- Download from VS Code's website.
- Follow installation instructions for your OS.
- Open VS Code terminal (Ctrl+`).
- Set username:
git config --global user.name "Your Name". - Set email:
git config --global user.email "your.email@example.com".
- On GitHub: Click 'New repository' > Name your repository > Initialize with a README (optional) > Create repository.
- Example: Creating "MyFirstRepo".
- Command:
git clone https://github.com/username/MyFirstRepo.git. - Clone via VS Code's source control panel.
git add <filename>orgit add .(to add all changes).git commit -m "Commit message".git push(to push to remote repository).git pull(to update local repository).git branch <branchname>(to create a new branch).git checkout <branchname>(to switch branches).
- Editing Files: Edit files in VS Code.
- Staging Changes: Use
git add. - Committing Changes:
git commit -m "Your message". - Pushing to GitHub:
git push.
-
Create and Switch to the New Branch Use the following command to create and switch to your new branch:
git branch new-branch-name git checkout new-branch-name
Replace
new-branch-namewith your desired branch name. -
Make Your Changes Edit, add, or delete files in your project as needed.
-
Stage Your Changes for Commit
git add .This command stages all your changes for the next commit.
-
Commit the Changes
git commit -m "Describe your changes"Replace
Describe your changeswith a message describing what changes you've made. -
Push the New Branch to the Remote Repository
git push -u origin new-branch-name
Replace
new-branch-namewith the name of your new branch. -
Switch to the Main Branch
git checkout main
-
Pull the Latest Changes from Main
git pull origin main
This ensures you have the latest changes from the remote main branch.
-
Merge the New Branch into Main
git merge new-branch-name
Replace
new-branch-namewith your branch's name. Resolve any merge conflicts if they arise. -
Push the Merged Changes to Remote
git push origin main
Remember to replace new-branch-name and main with the actual names of your branches. This guide will help you create a new branch, make commits, and merge it back into the main branch.