In today’s Ask the Admin, I’ll show you how to add branches to GitHub repos, create pull requests and deal with merge conflicts.
In GitHub for Windows – Installation, Adding Accounts, Committing Changes, and Syncing Repos on Petri IT Knowledgebase, I looked at the basics of working with repositories and GitHub’s desktop app. Today, I want to dig a little deeper and show you how to work with branches, generate pull requests to merge changes into the master branch, and resolve conflicts when collaborating with colleagues.
When you add collaborators to a repo, you give them permission to upload files to the server, and this sometimes results in two or more users making changes to code that results in conflicts during a sync operation. Good teamwork can help reduce the number of conflicts, but inevitably they will sometimes occur.
Resolving conflicts in GitHub for Windows (Image Credit: Russell Smith)
If a conflict is detected during a sync operation, you’ll need to resolve it manually, commit the files again, and then resync. Fortunately, GitHub for Windows displays conflicts directly in your files so that it’s easy to see where they’ve occurred and then remediate them.
Create a Branch
Probably you’ve noticed that by default you are working in the master branch. Branches are a key Git concept that enable workflow, and the master branch is always the final source code for your project that will be deployed.
Create a branch in GitHub for Windows (Image Credit: Russell Smith)
But it may be that you, or one of the repo’s approved collaborators, is working on a feature that needs testing, and this code shouldn’t be deployed to the master branch while it’s in development. Only once the code has been fully tested and approved, should it be merged with the master.
New branches are created off the master and should be named to reflect their purpose. For instance, 2factor-auth if the feature being worked on is to add two-factor authentication to your script or app.
Let’s create a new branch in GitHub for Windows.
- Open GitHub for Windows and select the repo you want to work with in the list on the left.
- At the top of the app, you’ll see that you’re currently working in the master branch. Click the icon to the left of the branch menu, give the new branch a name, make sure in the From branch menu that master is selected, and then click Create new branch.
- GitHub for Windows will now switch to the new branch.
Changes you make to files in the local clone of the repository can now be committed to either the master or 2factor-auth branch. If you click Publish in the top right of the GitHub for Windows, the new branch will be published in GitHub for others to access. After which point, you can click Sync to upload any further changes to the server.
Create a Pull Request
Now that you’ve got a new branch uploaded to GitHub, you’ll probably want other repo collaborators to review or work with you on the code before it gets merged into the master branch. Pull requests notify collaborators about the new code and asks them to review the commits and differences between the branch and the master.
Send a pull request in GitHub for Windows (Image Credit: Russell Smith)
- In the top right of GitHub for Windows, click Pull Request.
- In the Pull request panel in the right of the app, give the request a name, optional description and then click Send pull request. Note that any uncommitted changes in the current branch will be committed on sending the pull request.
- If you want to see the request in GitHub, click the View it on GitHub link.
Review a pull request in GitHub (Image Credit: Russell Smith)
Pull requests can’t be reviewed directly in GitHub for Windows, but you can click on the pull requests icon in the top right of the app to view pull requests on GitHub.com. If there are no conflicts with the master branch, you can merge the changes into the master by clicking Merge pull request on the pull request page in GitHub. Once you merge a pull request with the master, the request and sub branch are automatically deleted.
The post GitHub for Windows – Branches, Pull Requests, and Conflicts appeared first on Petri.