Using GitHub extension in Visual Studio to implement version control of your code

in #utopian-io7 years ago (edited)

What Will I Learn?

  • Learn the basic knowledge of Visual Studio extensions.
  • Learn how to using github extension in Visual Studio.
  • Learn the version control of the code.

Requirements

  • The basic knowledge of Visual Studio.
  • Basic C++
  • The basic knowledge of github.
  • Knowledge of code versioning.

Difficulty

  • Intermediate

Tutorial Contents

issue raised

The code version management system can be roughly divided into three Ages.

  • First age: Local mode, The main features of this period's management system include local code versioning, such as SCCs (1972), PVCS (1985), and so on.
  • Second age: Client-server mode, the main feature of this period's management system is to provide centralized server-side code versioning, such as CVS (1986), ClearCase (1992), Visual SourceSafe (1994), Perforce (1995) , Subversion (2000) and so on. The disadvantage is also quite obvious: you cannot view logs and submit and compare code versions without connecting to the server.
  • Third age: Distributed mode, the main feature of this period's management system is to provide distributed code versioning, such as Git (2005) and so on. Advantages of this generation: distributed management, which can still view logs, submit code, create branches without having a connection to the server, and support local branch.

Now our company is still using SourceGear as the manager of the code. But I personally prefer to use Git. My own Open-source code is usually uploaded to GitHub. It is believed that more people will use git soon to implement version control of the code.

github extension for Visual,From VS2015, Microsoft has integrated GitHub in Visual Studio to facilitate versioning of projects by developers.

The GitHub Extension for Visual Studio makes it easy to connect to and work with your repositories on GitHub and GitHub Enterprise from directly within Visual Studio 2015 or newer. Clone existing repositories or create new ones and start collaborating!

install github extension

Start Visual Studio and locate the Extensions and Updates menu (Tools-extensions and Updates), search the GitHub plugin online, and download it. Install the GitHub plug-in, which prompts you to restart immediately after the installation is successful and use the GitHub plug-in function.


Use GitHub in Visual Studio 2015

The use of GitHub in Visual Studio2015 is divided into several aspects: creating github repository, push update, establishing branches, commit updates, establishing PR, and updating from remote to local.

First you create a GitHub account and log in to visual studio. Create your GitHub repo and login
If you do not already have an account on GitHub then you need to create on. Create it and then come back to this point. Once created, use the credentials to login to your GitHub account.


1. create a GitHub repository from Visual Studio

Previously, if you needed to set up a repository, you had to create it on the GitHub home page or use the Git tool. Now that you have GitHub extensions, programmers can create repository directly on Visual Studio。

On the Team Exploer page of the Visula Studio page, you can see that you have logged into the GitHub account and a create menu appears below it. Click this button to enter the repository createing page. Enter the name of the repository, a description and the local location where you would like to store the source code. I use the default.

After this step, my GitHub account will have one more repository:

2. create a project to store in GitHub

Create a project for the repository. After clicking on the Create button and once the repository is created locally, you are prompted to create a Project to store into it.

As shown in the following figure, I build an MFC project named "Visualproject". The directory of this project is in the folder of the repository I just created. After this step, a project is added to the "solution" menu of my Team Exploer page.


You can use the GIT command to view the status of the current project at this time:

$ git remote show origin
    * remote origin
      Fetch URL: https://github.com/hushuilan/MyProject.git
      Push  URL: https://github.com/hushuilan/MyProject.git
      HEAD branch: master
      Remote branches:
        master  tracked
      Local branches configured for 'git pull':
        master  merges with remote master
      Local refs configured for 'git push':
        master  pushes to master  (local out of date)
        Administrator@CAXA-PC MINGW64 ~/Source/Repos/MyProject (master)

3. Add the source code to GitHub

Once the project is created, click on the Team Explorer tab, and expand the Project tree. Click on the Changes button. A list of the changed files will be listed here, and you will be able to see what changes you have made relative to the main code.

Clicking on the Changes button navigates to the page shown in following picture. Enter a description and press the Commit button. Commit means submitting your local Visual Studio changes to your GitHub repository.

My GitHub account has one more commit:

The command line that corresponds to this step:

git commit -m "commit my codes to github"

4. Synchronization code and push operations

Clicking on the Synch button navigates to the page. then select the commit you want to push, and then click the "Push" button on the new pop-up page to see the push progress.

At this point, my GitHub account project has been updated:

5. Establish a branch

If you want to do some specific function on a separate branch, you first need to set up a new branch, just select "Branch" in the main interface, then click on the tree to select "New", and then enter the name of the branch. Of course, you need to activate the branch to be effective.

The corresponding command for this operation is:

$ git branch branch1

6. Create PR

The main code can merge codes of this PR if you have created a PR. Add the following code to the VisualProject\VisualProjectView.h file:

// Operations
    public:
        BOOL DrawFunc();
        void DrawEllipse(int x, int y, int r);

Add the following code to the VisualProject\VisualProjectView.cpp file:

    void CVisualProjectView::DrawEllipse(int x, int y, int r)
    {
        CClientDC dc(this);
        CBrush brush, *oldbrush;
        brush.CreateSolidBrush(RGB(0xD1, 0xFB, 0xED));
        oldbrush = dc.SelectObject(&brush);
        dc.Ellipse(x - r, y - r, x + r, y + r);
        dc.SelectObject(oldbrush);
    }
    
   BOOL CVisualProjectView::DrawFunc()
    {
           //Draw what i want to show
            
           DrawEllipse(100, 100, 50);
            
           return TRUE;
    }

Now submit a PR. Submit the codes from branch1 to the main code.

You can use the git command to look at the status of the remote project at this time:

    $ git remote show origin
    * remote origin
      Fetch URL: https://github.com/hushuilan/MyProject.git
      Push  URL: https://github.com/hushuilan/MyProject.git
      HEAD branch: master
      Remote branches:
        Branch1 tracked
        master  tracked
      Local branches configured for 'git pull':
        Branch1 merges with remote Branch1
        master  merges with remote master
      Local refs configured for 'git push':
        Branch1 pushes to Branch1 (up to date)
        master  pushes to master  (local out of date)
        Administrator@CAXA-PC MINGW64 ~/Source/Repos/MyProject (master)

Thank you for your attention.
@hushuilan



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

👍👍👍👍

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @hushuilan I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.22
TRX 0.24
JST 0.038
BTC 95076.63
ETH 3277.51
USDT 1.00
SBD 3.26