Collaborating on git repositories: making pull requests and merging changes

Enes Turan
4 min readDec 7, 2022

(Isaac Vargas, 2020)

Git is a powerful and popular version control system that is widely used by developers around the world. It allows teams of developers to track and manage changes to their codebase, collaborate on projects, and maintain a history of their work. Git has many benefits for developers, including the ability to:

  • Track changes to your code over time, so you can easily see what has been added, modified, or deleted.
  • Collaborate with other developers on the same codebase, with the ability to merge and resolve conflicts between different versions of the code.
  • Create and manage multiple branches of your code, so you can work on different features or bug fixes simultaneously without affecting the main codebase.
  • Roll back to previous versions of your code if needed, so you can undo mistakes or recover from problems.
  • Host and share your code on remote repositories, such as GitHub, to make it easy for others to contribute to your project or use your code in their own projects.

In short, git is an essential tool for modern developers, providing a powerful and flexible way to manage and collaborate on code. It allows teams to work more efficiently and effectively, and to develop and maintain complex codebases with confidence.

Git Commands and Usage Examples

  • -a: This flag is used with the git commit command to automatically stage all modified and deleted files before the commit. For example, the following command will stage all modified and deleted files and then commit them with the message "commit message":
git commit -a -m "commit message"
  • -m: This flag is used with the git commit command to specify a commit message inline. The following command will commit all staged changes with the message "commit message":
git commit -m "commit message"
  • -s: This flag is used with the git commit command to add a "Signed-off-by" line to the commit message. The following command will commit all staged changes and add a "Signed-off-by" line to the commit message:
git commit -s -m "commit message"

“Signed-off-by” indicates that you have agreed to the Developer Certificate of Origin (DCO). This is often required by open source projects to ensure that all contributions are properly licensed and documented.

Here's an example of a commit message with the -s flag:

commit abc123456
Author: Enes Turan <enes.turan@example.com>
Date: Mon Jan 1 12:00:00 2021 -0500

Fix typo in README

-s

Signed-off-by: Enes Turan <enes.turan@example.com>
  • -b: This flag is used with the git checkout command to create a new branch and switch to it in a single command. The following command will create a new branch named "my-branch" and switch to it:
git checkout -b my-branch
  • -f: This flag is used with the git push and git pull commands to force the push or pull, overriding any merge conflicts. The following command will force push the current branch to the remote repository, overriding any conflicts:
git push -f origin my-branch
  • -u: This flag is used with the git push command to set the upstream branch for the current branch. The following command will set the upstream branch for the current branch and push your changes to the remote repository:
git push -u origin my-branch
  • -v: This flag is used with various git commands to enable verbose output. The following command will show verbose output when pulling changes from the remote repository:
git pull -v origin my-branch
(Isaac Vargas, 2020)

Create your first pull request

  • First, make sure you have a git account and are logged in.
  • Fork the repository you want to contribute to by clicking on the “Fork” button on the top right of the repository’s page. This will create a copy of the repository under your own account.
  • Clone the forked repository to your local machine using the following command:
git clone https://github.com/your-username/repository-name.git
  • Create a new branch for your changes using the following command:
git checkout -b branch-name
  • Make the necessary changes and commit them to the branch using the following commands:
git add .
git commit -s -m "commit message"
  • Push the changes to your forked repository using the following command:
git push origin branch-name
  • From your forked repository, create a pull request by clicking on the “New pull request” button on the top left of the page.
  • Fill out the pull request form and submit it. Your changes will then be reviewed and, if accepted, merged into the original repository.

Congratulations on completing your first pull request!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response