0% found this document useful (0 votes)
3 views

Files

Uploaded by

jet.fire.ch.021
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Files

Uploaded by

jet.fire.ch.021
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

4.1 What are Remote Repositories?

 What: A remote repository is a version of your project hosted on a server (like GitHub or GitLab) that enables
multiple collaborators to work on the same project.
 Why: Remote repositories are vital for sharing code, collaborating with team members, and serving as a backup.
They allow multiple people to contribute to a single project.
 How:
o Add a remote repository: git remote add origin <repository-url>
o View remotes: git remote -v
o Remove a remote: git remote remove <name>
 When to use:
o When you start working on a team project and need to push your work to a shared repository.
o When you want to contribute to an open-source project and track its progress.
 Example:
1. You create a new repository on GitHub.
2. In your terminal, initialize your local Git repo:
git init
3. Add the remote repository:
git remote add origin https://github.com/username/repo-name.git

4.2 Fetching and Pulling Changes


 What: Fetching gets the latest updates from the remote without applying them to your working directory.
Pulling combines fetching and merging the changes from the remote into your current branch.
 Why: These commands help you stay in sync with your team’s changes, ensuring you’re always working on the
most up-to-date version of the project. Fetching allows you to review changes before applying them, while
pulling merges them directly into your branch.
 How:
o Fetch changes: git fetch origin
o Pull and integrate: git pull origin <branch-name>
o View changes before pulling: git diff origin/<branch-name>
 When to use:
o Use fetch when you want to review the changes before applying them or if you’re not ready to merge
them yet.
o Use pull when you’re ready to integrate changes from the remote repository into your branch.
 Example:
1. Your teammate pushes changes to the main branch.
2. Fetch the latest updates:
git fetch origin
3. Review changes, and if you’re ready, pull them:
git pull origin main
4.3 Pushing Changes
 What: Pushing sends your local commits to the remote repository, making your changes available to others.
 Why: Pushing is essential for sharing your work with teammates, ensuring everyone has access to the latest
version of the project. It also serves as a backup of your progress.
 How:
o Push changes: git push origin <branch-name>
o Push a new branch to the remote: git push --set-upstream origin <branch-name>
 When to use:
o After you have committed your changes locally and are ready for them to be available to the rest of the
team.
o When creating a new feature branch that needs to be accessible by others.
 Example:
1. You’ve made and committed changes locally.
2. Push those changes to the remote:
git push origin feature-branch
3. If it’s a new branch:
git push --set-upstream origin feature-branch
4.4 Forking and Pull Requests
 What: Forking creates a copy of another user’s repository in your own GitHub/GitLab account. A Pull Request
(PR) is a request to merge changes from your forked repository into the original repository.
 Why: Forking allows you to work on someone else’s project without directly affecting the original codebase. Pull
Requests are used to propose changes back to the original repository after you’ve made improvements or fixes.
 How:
o Fork a repository on GitHub by clicking the "Fork" button.
o Clone your forked repository: git clone <forked-repo-url>
o Make changes, commit them, and push to your forked repository.
o Open a pull request by selecting "New Pull Request" on the original repository.
 When to use:
o Use forking when you want to contribute to an open-source project or work on a copy of someone else’s
repository independently.
o Use a Pull Request when you’re ready to propose your changes to the original repository.
 Example:
1. You want to contribute to an open-source project.
2. Fork the repository on GitHub.
3. Clone your forked repository:
git clone https://github.com/yourusername/forked-repo.git
4. Make your changes, then commit and push them:
git add .
git commit -m "Added new feature"
git push origin main
5. Create a pull request by navigating to the original repository and clicking “New Pull Request.”

You might also like