Contributing to a GitHub Project7:55 with Ben Deitch
Android Studio provides many tools to make working with version control as painless as possible. In this video we'll see how we can use these tools to help us contribute to a GitHub project.
Let's get back to our original project. 0:00 The first thing I want to point out is the version control button on the bottom. 0:02 This button gives us quick access to some important version control options. 0:05 It starts on the local changes tab, 0:09 which shows us a list of our uncommitted changes. 0:11 It's empty for now, but once we make a change, we'll be able to see it here. 0:14 Over on the Log tab, we can see a history of all the commits on the project 0:19 starting with the most recent commits on top. 0:23 Scrolling to the bottom, 0:26 we can see that the initial commit was made on July 24th at 7:22 AM. 0:28 Scrolling up a bit, we can also tell that when fact selection was refactored, 0:33 it was done on a new branch which was later merged back into the master branch, 0:38 leaving us with the one branch we have now. 0:43 Now that we've got a feel for the project, let's start making some changes. 0:45 The first change we'll make is to add another background color. 0:49 I've already found a good gold color for us to use. 0:52 Let's create a new branch for this change called add gold color. 0:55 Using branches is a good idea, 0:59 because it allows many developers to work on the same code change 1:01 while keeping the master branch unharmed by development that isn't yet ready. 1:04 To make a new branch we'll open the VCS menu, pick the Git option, 1:08 open the Branches menu, and, then click New Branch. 1:14 Then we type in the name of our branch, add_gold_color, and hit OK. 1:20 If we look at the log, we can see our new branch was created, 1:26 and we're currently on it. 1:29 Adding the gold color will be done in the color wheel class. 1:31 Let's type CMD+O on Mac or Ctrl+N on Windows to show the open class dialog. 1:34 Type in colorwheel and hit Enter to open it. 1:40 Now that we're in the color wheel class we can add our gold color to 1:48 the bottom of the colors array. 1:51 We'll be using ddca8b as the color. 1:53 And we can add it to the bottom like so. 1:58 Hopping over to the Local Changes tab on the Version Control menu, 2:11 we can now see that our change is listed. 2:15 If we're curious about why a file is showing up here, we can right-click it and 2:19 select Show Diff. 2:23 This shows us the differences between the new and old versions of the file. 2:26 As expected, it only shows the change we just made. 2:30 Now we can click the up arrow VCS button or 2:34 hit CMD+K on Mac or CTRL+K on Windows to commit our change. 2:37 Add a quick commit message. 2:44 And hit Commit. 2:48 Warnings are fine to ignore. 2:51 Let's hit Commit again. 2:53 Looking at the log again, we can see that our add_gold_color branch is now one 2:57 commit ahead of the master branch. 3:01 Let's add another color, but this time let's add it in the master branch. 3:04 Typically, we wouldn't do development in the master branch, but 3:08 we'll let it slide so we can see how to resolve a merge conflict. 3:12 To switch back to the master branch, we can open up the Branches menu 3:15 click on the master branch, and then click Checkout. 3:19 Looking back at the log, 3:24 we can see that the head tag has been moved to the master branch. 3:25 The color we'll be adding this time is a bronze color. 3:28 Back in the color wheel class, 3:31 let's add 8b4513 to the bottom of the end colors array. 3:33 The gold color isn't yet on the master branch. 3:49 It will show up once we merge the branches. 3:52 But for now, let's go ahead and commit our most recent change. 3:55 We'll change the commit message to say bronze, and hit Commit. 4:00 The log now shows that the master branch is ahead of the add_gold_color branch, 4:08 and it's a bit more obvious that add_gold_color is a separate branch. 4:14 At this point, the add_gold_color branch is finished, and 4:18 we should probably merge it back into master. 4:22 To merge, we'll open the VCS menu, pick the Git option, and select Merge Changes. 4:24 Then we select the branch we want to merge into our current branch, 4:33 add_gold_color, and hit Merge. 4:36 Normally this wouldn't encounter a conflict, but 4:42 it looks like we've got a merge conflict we'll need to resolve. 4:44 Let's click the Merge button to start resolving the conflict. 4:48 In this view we have the changes from the current branch master on the left, 4:52 the changes from the branch we're trying to merge on, add gold color on the right. 4:57 And the merge result in the middle. 5:02 It looks like the problem is on line 23. 5:05 One version says that line should be bronze, and 5:07 the other version says it should be gold. 5:10 To resolve this, we can pick one of the two branches and 5:12 ignore the other branch, or we could combine them ourselves. 5:15 Clicking the angle quotes, will apply the change, and 5:19 clicking the x will ignore the change. 5:22 We'd like to keep both changes. 5:25 So let's click the angle quotes next to both branches. 5:27 Now that we've processed both changes, Android Studio thinks we're done merging, 5:33 and asks if want to save and finish. 5:37 But if we take a closer look, 5:39 it didn't do a great job of merging the two changes together. 5:41 Let's click Continue and fix our merge result into something that 5:45 makes a bit more sense, mostly getting rid of the duplicate light gray row. 5:48 That looks better. 5:56 Now we can click apply to resolve the conflict. 5:58 Next we can commit the changes and 6:02 accept the default message about merging the brands. 6:03 We're done making changes and everything has been committed locally. 6:13 It's now time to push our commits to GitHub. 6:18 Let's open the VCS menu, pick the Git option, and pick Push. 6:21 Everything looks good, 6:29 let's hit Push again to send our local commits out to GitHub. 6:30 Great, now our changes are on our forked GitHub project. 6:36 The last step is to get those changes into the original GitHub project. 6:39 We'll accomplish this to a pull request. 6:43 Back in our familiar Git menu, 6:46 we can pick the create pull request option to initiate a pull request. 6:49 Let's change the title to something a bit better. 7:04 Add a short description. 7:10 And click OK. 7:15 Now we can click on the link to see our pull request. 7:19 Looks great, now the owner of the project will be able to merge our changes 7:26 into the original project. 7:30 Hopefully, you've now got a good understanding of how Android Studio can 7:33 make help make some typical GitHub tasks just a little easier. 7:37 It's definitely nice to not have to do all of this from the command line. 7:42 If you do get in to trouble, don't hesitate to jump into the command line. 7:46 There are many options, and commands, which have yet 7:49 to be integrated into Android Studio. 7:52
You need to sign up for Treehouse in order to download course files.Sign up