Git Push and Pull Request | Bondar Academy
Course: Git and GitHub Fundamentals
Module: Working with Git and GitHub
Instructor: Artem Bondar
Lesson Summary
In this lesson, we will learn how to authorize Visual Studio Code with your GitHub account, push code to GitHub, and create a pull request. Authorization Steps To authorize Visual Studio Code: Open Visual Studio Code and click on the accounts icon. Select Backup and Sync Settings . Click Sign In and choose GitHub . Enter your GitHub username and password in the browser and authorize Visual Studio Code. Pushing Code to GitHub Once authorized, you can push your code branch: Use the command git push . If prompted with an error about the upstream branch, set it using: git push --set-upstream origin first-code Authorize again if needed. Creating a Pull Request After pushing, navigate to your GitHub repository: Click on Compare and Create Pull Request . Provide a title and description for your pull request. Good descriptions help reviewers understand your changes. Reviewing Commits In the pull request, you can: View all commits and changes made. Provide feedback or ask questions on specific lines. Merging Changes Once reviewed, you can: Merge the pull request if there are no conflicts. Delete the branch if it is no longer needed. Updating Local Repository To sync your local master branch with remote: Switch to the master branch using git checkout master . Run git pull to fetch the latest changes. This concludes the process of pushing a branch to GitHub, creating a pull request, and merging changes into the master branch.
Video Transcript
In this lesson, we will authorize Visual Studio Code with your GitHub account, then we will push your code to GitHub and we create a first pull request. All right, let's jump into it. All right, so we continue working on our first sample branch, first code branch, and we will push this branch right now to a remote repository. In order to do that, your terminal or your Visual Studio Code, first of all, have to be authorized to be able to push any changes to the server. The most easiest way to authorize Visual Studio Code and terminal inside of the Visual Studio Code is to simply log in to the GitHub account using Visual Studio. So click on this little icon with accounts and click on backup and sync settings. Click on that. Here on the top, you will see a sign in button. Click sign in. And here, sign in with GitHub and click enter. After that, you will be redirected to a login page in the browser where you need to enter your username and password and click sign in. And then you need to perform this authorization, authorize Visual Studio Code and open back the Visual Studio Code. So that's it. So simple. Now, if we click on this user icon, then we can see that Git User Bonder Academy is logged in with Visual Studio Code. Visual Studio Code is now authorized. Now we can perform git push command to push our first code branch to remote repository. I type git push and we see the message that the current branch, first code, does not have upstream branch. It means that Git is trying to find the first code branch on remote repository, but not able to, so it cannot push this branch. So let's set this upstream branch with this line. I copy this line, paste it right here, git push, set upstream origin, first code and hit enter. Visual Studio asking me again to navigate to the GitHub and asking me for a few more permissions. And I just click authorize and navigating back. All right, it was successfully done. Now we can navigate to the repository and review this branch over there. Here we go. This is our GitHub repository and we immediately see a new message pops up, that first code branch, and it's offering us to compare and create a pull request. But before we jump into that, let me show you a little bit around. So if we click here on the list of the branches and click on view all branches, now there is a new branch available. The master is a default branch, your branch is first code and active branch is exactly the same branch. So also a little chart over here, which says zero and three. This little chart shows that we have zero commits behind the master and three commits ahead of master. It means the first code branch in sync with the newer changes from the master branch. So it has zero commits behind, and the first code branch has three new commits that master branch does not have. And we can create a pull request to the master branch. We can create either over here, or if we go back to our project, we can click on compare and pull request. I click on this button. Now we need to provide the title and description for the pull request. For example, this is our first pull request. In description, we can say created a text file with two phrases. Title and description is very important when you work collaboratively together with the team. Because when somebody will review your code, first they want to read what this code is about before jumping in actual code and reviewing it. So you usually provide a good description. What did you do? Why did you do that? And what your code is doing? So the person who is reviewing your code knows what to expect and what to pay attention on. And you click a button, create pull request. All right, so pull request is open. We see the status. And what do we have here? Pull request is showing us all three commits. Commit number one, number two, and number three that we have created. We also have this commit stub. They are displayed right here. We see a user who created those commits. It was you. And we can review those commits one by one. For example, the very first commit is this one. If I click on this thing, we see only one phrase is displayed over here. If I go back and click on the second commit, now we see a new change. So this one was removed and these three lines were added. So this is a minus and we have three pluses. And if we go back to the last one, and now we can see that this sentence was modified. Before it was, this is a second phrase. And in this current commit, it was changed to, this is a second word. And by looking into this commit, you can easily tell what was exactly changed. And if someone wants to provide the feedback or ask any questions, you can simply click on the plus button and ask the questions. Why did we need this change? Something like that. And start a review. And waiting for you to provide the feedback on why this change was needed. Going back. And now in the main window of the conversation, you can see this conversation going. So this conversation is related to testfile.txt, to this particular line of code. This is the question and you can provide feedback. This is what I planned to do. Something like this. And comment. All right, the answer is provided and it looks like everything looks fine here. Also, Git checking for us, do we have a conflicts with the master branch or not? So Git is saying that no conflicts were found. And you can click on this button, merge pull request. Confirm merge. And the branch first code was successfully merged into the master branch. And after that, we can safely delete the branch because we don't need it anymore. This branch did this job. Click delete branch. All right, going back to the code. We are on the master branch and what we have here, here we go. This is the testfile.txt, which was created on our test branch. And now it's merged successfully into the master branch. And let's go back to Visual Studio Code. In Visual Studio Code, we're still here on the first code branch. So let's change to the master branch. You can do Git checkout master or you can use Visual Studio Code user interface. Just click on first code and click on master. Now here is interface also changed. You can see that testfile.txt is highlighted like it does not exist. And it's actually does not because in the current master branch on the local computer, this file does not exist yet. This file exists on our branch. This file already exists in the master branch on remote repository, but it does not exist yet on our local computer because we need to pull those changes from remote repository to our computer. And also look at the bottom corner, user interface of Visual Studio Code is telling us that we have four changes or four commits that are in origin master branch, but are not in our current master branch. We need to execute command git pull to pull those changes from the master branch. Git pull, hit enter. And all the changes were pulled successfully. We can see that one file changed, three commits, and testfile.txt is available in the master branch. All right, so this is the process, how you push your branch to GitHub repository, create pull request, perform code review, merge your changes into the master branch, and then pulling back your changes to the master branch on the local computer. All right, that's it guys. And see you in the next lesson.