Git is a version control system, a tool for collaborative software development. 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 essential because:
- Keeps the development history.
- Controls access rights to shared code.
- Provides version control of the software product.
Git was developed by Linus Torvalds to make it easy to create a 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, such as SmartGit. Since Git core is a command-line package, it is also convenient to use it directly from this location. The functionality will be the same both in working with the web service and ingraphic client. Beginners are advised to delve into the study of the console version - this will help you understand the commands and internal structure much faster.
Next, we will analyze in detail one of the Git commands - Pull Request.
Pull request is a proposal to change the repository. This mechanism is used in 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 must take the following steps.
Git: how to make a pull request
- Fork command - create a local copy of the working repository.
- Finish or modify your copy.
- Pull request command - propose changes in the code to the owner of the repository.
- Merge command - with the help of it the owner of the repository approves changes.
- Git pull request can be created in two ways. The first is through the console, the second is using the capabilities of the web service where your repository is located.
Pull Request is a feature exclusively in the GitHub Git client that relies on the request pull console 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 propose changes to the project to the owner of the repository, you must:
- Go to the branch containing the originalfile.
- Press New pull request.
- If changes have been made, the Comparing changes window will open.
- In it you can specify the path, from which branch of which repository and where 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 change notification in the Pull requests tab.
The owner, in turn, can execute a "merge pull request" on the Git repository. This will implement the changes suggested by the upstream developer.
It's also pretty handy to use the Git console client. A Pull Request is made through a 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, enter the following commands:
- Command git add NewFile.cxx - add a new file to the local repository.
- Command git commit -a -m commit message - create a commit, specify the changes in the project in the commit message.
- Git push origin command - making changes to the remote repository (you need to confirm your login 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.
In Git Merge, a pull request is a command to merge a development branchfeature with the main branch (master). There are two merge patterns:
- True fusion. Occurs when several changes need to be made to the upstream 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 branches, then the master pointer is rewound forward, and is set to the one pointed to by the feature branch.
Working with Git
When working with Git, it is always important to remember that there are two repositories - local and remote. The 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 a connection to a remote repository. Of course, it is impossible to do "pull request" locally in Git.
Pull performs the merge if the remote and local histories differ.
The Push operation sends all changes that are not in the remote repository. If there are new commits in the remote repository, 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.