Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Technical Seminar Series: GIT Pull Requests Best Practices


Published on

Continuing with our ‘Technical Seminar Series’, another noteworthy seminar was conducted on ‘GIT Pull Requests Best Practices’ on the 10th of July by our senior developer evangelist Hitesh Kumar. More than 40 enthusiasts attended this session.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Technical Seminar Series: GIT Pull Requests Best Practices

  1. 1. GIT PULL REQUEST - Hitesh Kumar
  2. 2. ▪ What is Pull request? ▪ Why do we need to create pull request? ▪ What is use of GIT branch? ▪ How to write code in Php? (only to make code readable) ▪ How to create Pull Request ? ▪ Adding line comments to a pull request Key Points
  3. 3. What is pull request? A pull request is short for “requesting for a Git Pull”. Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes and add follow-up commits before your changes are merged into the base branch.
  4. 4. This can be confusing to understand, so we’re going to explain it with an analogy. Imagine you have a crate of bananas that you want to load onto a ship. The only way to load the bananas is: 1. You get someone to throw down a rope 2. You tie the rope to the crate 3. They pull the crate up When they pull the crate up, they’ll want to check whether your bananas are good. If they spot a rotten banana, they might want to request you change that rotten banana for a good one.
  5. 5. They might also think that all your bananas suck and decide to throw them away. (But let’s hope this doesn’t happen, shall we?) In this analogy, the crate of bananas is your code from the develop branch. The ship is the master branch. The sailor is here to check whether your code is good enough for the master branch. That’s what a pull request is: You get someone to check your code before merging into another branch. The only difference between our analogy we used and an actual pull-request is: You don’t ask someone to throw a rope down for you. You bring the rope yourself, you tie it to your bananas at the harbour, and you throw it onto the ship. The only thing the sailor needs to do is check the bananas. This is what we mean by submitting a pull request.
  6. 6. Why do we need to create pull request? A Pull Request represents a way to deliver value to the application in the form of a set of changes that together form a high-level concern
  7. 7. A Pull Request is not just a way to "prepare" a set of commits so that it can be sent to the owner of another copy of the project through external means (such as e- mail). A Pull Request is the set of commits, that also contains the technical history of everything that was related to that Pull Request. All in a single place.
  8. 8. What is use of GIT branch? In very simple terms, git branches are individual projects within a git repository. Different branches within a repository can have completely different files and folders, or it could have everything the same except for some lines of code in a file.
  9. 9. Let’s use a few real world examples (at least that I’ve used before, others may have used them differently): ● Pretend you submitted a research article to a journal and they want you to revise it based on some reviewers comments. There are several ways to deal with the comments, so instead of changing your main manuscript, you create a revision branch in your manuscript git repository. In that branch you make the changes to your manuscript in response to the reviewers. Once you are satisfied, you merge the branch into the master branch and resubmit the article. ● Imagine you have a dataset that multiple people work off of but that is also often updated with more data. You think you found a problem with the dataset, but aren’t sure. So you create a new branch fixing to fix the problems without messing with the master dataset. After you confirm the problem is real and that you have the solution, you submit a pull request of the fixing branch to be merged with the master branch. ● What is often the case in software development, a bug or missing feature in the software gets identified. Because the software is already in production use (fairly stable, other people rely on it, etc), you can’t just make changes to the main software code. So a hotfix or feature branch is created to address these problems, which will eventually get merged in with the master branch for the next version of the software. This ensures that other people’s code isn’t broken everytime a bug gets fixed.
  10. 10. COMMANDS USED WITH BRANCHES Branches are best understood visually. So let’s first start with using this website to see what the branch, checkout, and merge commands are doing. After we’ve tried that, let’s do it locally (on your own computer). Here is a sequence of commands to try out: ● cd - change directory ● directory - the same thing as a folder ● mkdir - make a directory ● echo - print a message to the screen or to a file if > (redirect) is present. ● git init - start or initialize a git repository ● git add - put a file into the staging area, so that git starts tracking it ● git commit - send files in the staging/index area into the history (the git repository) ● git log --graph --oneline --decorate --all - view the commit history in the git repository and the branches, with each commit as one line. ● git branch - An individual line of commit history that contains files that may differ from other branches. ● git checkout - A way to move across the git commits and branches. ● git merge - Combine a branch into the current checked out branch (i.e. the branch you are on).
  11. 11. USING BRANCHES FOR PULL REQUESTS I mentioned this already, but branches are best used when doing a pull request (unless the pull request is very small or few people work on the repository). The steps to take would be: 1. Fork a repository on GitHub 2. Clone it onto your computer 3. Make a branch and move to it: git checkout -b fixingBranch 4. Make changes to the files 5. Commit the changes to the history 6. Push the branch up to your forked version: git push origin fixingBranch 7. On GitHub, submit a Pull Request of your fixingBranch 8. Once the pull request is merged, delete the fixingBranch on your forked repo on GitHub and on your computer (git checkout master && git pull upstream master && git branch -d fixingBranch)
  12. 12. How to write code in Php? Only to make code readable not about logic
  13. 13. How to create Pull Request ?
  14. 14. Before we submit a pull request, we need to make some changes, so we have something to merge. In this case, we’re going to add a heading to the code: You need to commit this code into the develop branch. Then, you need to push it to the git remote. f It’ll appear in the section I highlighted in the image below. If you see the message, great. Click on it. You’ll save a few steps. If you don’t see it, you can click on the pull request tab at the top of your Github repo.
  15. 15. Then, click on the green button that says “new pull request”.
  16. 16. You’ll come to a page that says “Compare changes”. To create a pull request, you want to set the base and compare branches to the following: ● base: branch you want to merge to ● compare: branch you want to merge from In our case, we want to merge to master, so we’ll set base to master. We’re merging from develop, so we’ll set compare to develop. Once you’ve selected your branches, Github will show you the list of commits that have been made. Here’ what you need to do is click on the “Create pull request button”.
  17. 17. Github will show you a page that says “Open a pull request”. Note: This is the page you’ll arrive at if you saw the “Your branch has been updated X minutes ago” message I talked about earlier.
  18. 18. The title you write will be the title people see in the pull request tab. We’re going to set it to “Add a heading to the index”. For the comments, it’s going to be the first message people see when they clicked into the pull request. In this case, we’ll say “I’ve added a heading. Let me know if its good?”.
  19. 19. Once you’ve added the title and message, you can click on the Create pull request button at the bottom of the page. Now, if you click on the pull request tab at the top, you’ll an open pull request that we’ve just submitted. This is how you create a pull request
  20. 20. Adding line comments to a pull request
  21. 21. Visit the below link to add the line comment in changed files. request
  22. 22. Thank You