Last Update: Sep 04, 2024 | Published: Aug 03, 2016
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.
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.
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.
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.
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.
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.
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.
Related Article: