Creating Pull Request in Git

Git is a version control system, a tool for joint development of a software product. Any team software development needs a convenient tool for tracking the work done and the changes made, fixing those responsible for the correction, creating the possibility of coordinating developments or rolling back in case of errors. Git is indispensable because:

  • Keeps development history.
  • Controls access rights to the shared code.
  • Provides version control of a software product.
Git system




Git was developed by Linus Torvalds to simplify the creation of the Linux kernel. There are several ways to manage a project through Git: you can use web services such as GitHub, or download a graphical Git client. There are several free clients for any operating system, for example, SmartGit. Since the core of Git is a command-line software package, it is also convenient to use it directly from this location. The functionality will be the same both in working with a web service and in a graphical client. Beginners are advised to delve into the study of the console version - this way understanding of commands and internal structure will come much faster.





Desktop client




Next, we will take a detailed look at one of the Git commands - Pull Request.

Pull request is a suggestion for changing the repository. This mechanism is used in the general work on software products. Allows you to coordinate the activities of developers and avoid confusion. Anyone who wants to modify or modify an existing project should take the following steps.

Git: how to make pull request

  • The Fork team is to create a local copy of the working repository.
  • Modify or modify your copy.
  • The Pull request command is to propose changes to the code to the owner of the repository.
  • Merge Team - Using it, the repository owner approves the changes.
  • On a Git system, pull request can be created in two ways. The first - through the console, the second - using the capabilities of the web service on which your repository is located.

Pull Request is a feature of the GitHub Git client exclusively, which relies on the console request pull command. If you need to make a pull request through the console, you need a web API application, such as hub. You can make a pull request for GitHub from a desktop application if it supports the GitHub API.

Git web service: create pull request

To suggest changes to the project to the owner of the repository, you must:





  • Go to the branch containing the source file.
  • Click New pull request.
  • If changes were made, the Comparing changes window opens.
  • In it, you can specify the path from which branch of which repository and where you want to send changes.
  • Click Create pull request.
  • It is advisable to clarify in the appropriate fields what changes have been made.
  • Now the owner of the repository will see a notification about the changes in the Pull requests tab.

The owner, in turn, can execute "merge pull request" in the Git repository. This will make the changes proposed by the developer with the main branch of the project.

Development branches




Using the Git console client is also quite convenient. Pull Request is done through the web service, if the GitHub API is not installed, the algorithm for making changes to the remote repository will be shown below. To make changes to the remote repository through the console, after correcting the code, you must enter the following commands:

  • Git add NewFile.cxx command - add a new file to the local repository.
  • The git commit -a -m commit message command - create a commit, specify the changes in the project in the commit message.
  • The git push origin command - making changes to the remote repository (you must confirm your username and password).
  • Next, you also need to use the web version of Git that hosts your remote repository and create a pull request using the guide above.

Merge

In Git Merge, pull request is a command to merge a feature development branch from a master branch. There are two merge patterns:

  • True fusion. Occurs when it is necessary to make several changes to the main development branch. That is, a new commit is created in the master branch, which refers to several of the same attributes from feature.
  • Rewind If the commit history turned out without branching, then the master pointer is fast-forwarded, and set to the one pointed to by the feature branch.
Development Patterns




Work with git

When working with Git, it is always important to remember that there are two repositories - local and remote. A local one is created on the developer's machine after the clone command, for example, if the developer wants to join the project. That is, you can work with the version control system without an Internet connection, only the pull and push commands will require communication with the remote storage. Locally in Git, "pull request" is, of course, impossible to do.

The Pull operation merges if the stories are remotely and locally different.

The Push operation sends all changes that are not in the remote repository. If new commits happen to be in the remote repository, then the operation will fail.

That is, locally, the developer has a master branch, which is the last change, and the origin / master branch is the state of the remote repository after the last Pull or Push operation.




All Articles