Git Exercises

Ques.5- Review the changes made by your partner and merge them into your branch

Ans- To review the changes made by your partner and merge them into your branch using Git, follow these steps:


1. Ensure that you have fetched the latest changes from the remote repository using `git fetch <remote_name>`. Replace `<remote_name>` with the name of the remote repository, such as `origin`.

2. Check out the branch where you want to merge your partner's changes. For example, if you want to merge into the `main` branch, run the command:

$ git checkout main


3. Run the command `git log <remote_name>/<branch_name>` to view the commits made by your partner in the remote branch. Replace `<remote_name>` with the name of the remote repository, and `<branch_name>` with the name of your partner's branch.

$ git log origin/partner-branch
This will display the commit history and the changes made by your partner.


4. Once you have reviewed the changes and are ready to merge them into your branch, run the command `git merge <remote_name>/<branch_name>`. Replace `<remote_name>` with the name of the remote repository, and `<branch_name>` with the name of your partner's branch.

$ git merge origin/partner-branch
Git will attempt to merge the changes from your partner's branch into your current branch. If there are conflicts, you will need to resolve them manually.


5. If there are conflicts, open the conflicting files in a text editor and locate the conflict markers (`<<<<<<<`, `=======`, and `>>>>>>>`). Edit the files to resolve the conflicts, keeping the desired changes and removing the conflict markers.

6. After resolving the conflicts, save the files and stage them using `git add <file>` for each resolved file, or use `git add .` to stage all changes.

7. Once all conflicts are resolved and staged, run the command `git commit` to create a merge commit with the resolved changes.

8. Provide a commit message describing the merge and save the commit.

9. Finally, push the merged changes to the remote repository using `git push <remote_name> <branch_name>`. Replace `<remote_name>` with the name of the remote repository, and `<branch_name>` with the name of your branch.

$ git push origin main
Git will push the merged changes to the remote repository, making them available to others.


By following these steps, you can review the changes made by your partner, merge them into your branch, and push the merged changes to the remote repository using Git.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext