This Tutorial Explains how to Download and use the GitHub Desktop to Collaborate With GitHub From Your Desktop for Efficient Version Control:
As we all know, GitHub provides a website to host Git repositories. In our previous tutorials on GitHub, we have seen the developer’s activities on versioning files mostly on GitHub.
There is also a Git Client wherein the developers can work on the repository offline on their local machines using git commands from the command prompt or git bash, make changes and push it back to the remote repository on GitHub.
What You Will Learn:
Though the Git commands executed from the command line are great from a learning point of view, there is a good user interface to work on the local repositories i.e. GitHub Desktop.
GitHub Desktop for Windows can be downloaded and installed from the following URL
Launch GitHub Desktop
Work With The Remote Repository
Once the GitHub desktop is launched, we can start by cloning the remote repository to the local machine, make changes and push it back to the remote repository.
In GitHub Desktop, go to File => Options and ensure your GitHub account is setup.
In GitHub Desktop, to clone a repository select File => Clone Repository
Go to the URL tab and enter the remote repository details in the form of the GitHub Username/repository. Click on Clone.
Now as the repository is cloned to the local machine, we can open the local repository contents using command prompt or explorer or even Atom editor if installed and make changes to the files.
Make changes to the files and save the same.
Back in the GitHub Desktop, you can see the RED marking which specifies if the lines were added or were deleted.
Add a Summary and Co-authors if needed and click on Commit to master at the bottom.
You will notice that most of the git commands that you execute from the command prompt have been done through the user interface.
We can now push the changes to the remote repository in GitHub. Click on Push origin.
Now the changes are visible in the master branch. To ensure that the changes are merged to the feature branch we will need to create a Pull Request.
Switch to the feature branch and create a Pull Request.
Click on Create Pull Request.
You are then re-directed to GitHub to create the Pull Request.
Proceed to create and merge the Pull Request and then finally pull(sync) the changes to your local repository.
From the Repository, the menu selects the Pull option.
Now the local repository would be in sync with the remote repository.
Create A New Local Repository And Branch
In the previous section, we learned about working with the remote repository by cloning it. Using GitHub desktop, we can also create a new local repository and push or publish the same to GitHub.
Click on File =>New Repository
Enter the name of the repository and the local path. Click on Create Repository.
As the repository is created, you can also create a branch before you publish/push the changes to GitHub.
Select New branch from the Branch menu. Call it to feature and click on Create branch.
Now we do have 2 branches and we can proceed to Publish / Push the changes to GitHub. Click on Publish repository.
Click on Publish Repository.
As there is also a Feature branch, you must publish the feature branch as well. Now the changes can be made to the files locally and then push the changes to the remote repository. Changes in the remote repository should also be in sync with the local repository.
Merge Changes In Local Repository
Assume that there are changes in the feature branch in the local repository. We can merge the changes to the master branch. Post this we should push the changes of the master and feature branch to GitHub.
Make a change to a file in the feature branch and commit the same.
Push the changes to the remote repository.
Switch to the Master branch and click on Branch =>Merge into the current branch.
Select the Feature branch which is the source branch. Click on the Merge button.
Once the changes are merged into the master branch, you can then push the changes to the remote repository to be in sync.
All the changes committed to branches in the local repository can be merged and pushed to the remote repository to be in sync.
There could also be a scenario where the changes have been committed to a file in the remote repository and also a change to the same file locally. In this case, the conflicts would be seen and would need to be resolved to have both the remote and local repository to be in sync.
Remote repository changes committed in the Master branch
Local repository changes committed in the master branch
As the changes are committed to the local repository, you can now push the changes to the remote repository. The conflicts will be seen while doing this. Click on Push origin.
The following message would appear as there are changes in the remote repository to the same file. Click on Fetch.
Now click on Pull origin.
In the screen that comes up, you can open the file in your editor and resolve the conflicts. In this case, we are opening the file in explorer and resolving the conflicts.
Fix all of the conflicts by retaining the appropriate content and removing the others with markers. Once the conflicts are resolved, you can commit the merge.
Now push the changes back to the remote repository. The local and remote repository is now in sync. As the changes have been done on one branch you can then create a Pull Request to merge the changes to the other branches.
Looking At History
You can also look at the history of changes done so far to the repository. Toggle to the History tab.
Suppose you have done changes to a file in the master branch, you can then compare it with any of the other branches. Select Branch => Compare to branch.
Select the feature branch to look at the changes.
Though the use of Git commands from the command line is great, we saw in this GitHub Desktop tutorial, how a great Git Client like GitHub Desktop with a good user interface can ease the developer’s work while working with the local and remote repositories.
In the upcoming tutorial, we will look at another Git client interface Tortoise Git that integrates with the Windows Explorer Shell.