Lets get started publishing our VS2017 code to GitHub. If your IDE is not yet configured to use GitHub, read this article as a starter. There are two ways to start contributing to the open source community via GitHub : clone or fork an existing repository and start contributing and publish a new repo on GitHub.
Creating a New Repository in GitHubCreate a new blank solution. Make sure the Create New Git Repository option is checked.Once created, this will only reside on your local machine until we publish it online. Go ahead and add a simple console app and test before start committing. Note that VS2017 will automatically add a .gitignore file for the project.
The Team Explorer pane should be displaying the new repo on the Local Repositories section. Double click on the repo to access the available actions.
- Changes - Use this to view code changes you have made in the project.
- Sync - Use these to initiate syncing between repositories. Such as fetching, pulling or pushing changes to GitHub.
- Branches - Let you manage the branches in your repo.
- Settings - Let you manage global and repository settings.
Lets view the changes on the repo. The pane will display all new files added to the project but is not yet part of the repo. The UI also allows us to commit these changes right away.
There are three options provided when committing changes : Commit All, Commit All and Push and Commit All and Sync.
A discussion on StackOverflow regarding this can be found on this link.
For this tutorial, lets do simple Commit All. To publish the repo to GitHub, click on the Sync option and select Publish to GitHub. You may need to enter your credentials.
Once the repo is published, the Home page on the Team Explorer pane will be updated to display the link to the online repo and new available actions.
Your GitHub page will now include your new repo. By default, this is a public repo, thus, anyone can fork or clone it.
Pushing your changes to GitHub
The first section discussed the initial phase of the process. Now that the repo is available online, we can continue adding functionality to our app and push changes to GitHub as needed. For this section, we assume that no other changes on the online repo and we are pushing our fist update. Go ahead and make some changes to our app. You should notice that the IDE marks those changes on the source code view as well as on the files view. The Changes view will display those changes and for this time we can do Commit All and Push. Once Push is completed, the update will be reflected on GitHub.
Pulling changes from GitHub
For simple changes without any conflicts, a Sync operation will do the trick on the Synchronization page. But for clarity, we will do a Fetch and a Pull to show the changes.
Fetch operation updates only your remote-tracking branches. It does not update the codes you are working on. A pull operation is a Fetch followed by Merge action. This will automatically bring your codes up to date with the remote branch. For this sample, we do Fetch first to show the changes. The Synchronization page will display incoming commits from the remote repo.
To view the changes related to the incoming commit , right click the commit entry and select View Commit Details.
Once everything is ok, you can select Pull action to update your working code.
This tutorial discussed simple git operations. This may not be enough once the project get big and a number of developers is added.