If your project is stored only on your disk, then with the breakdown of the disk you are in trouble. Even a regular backup can not always save you.
Some developers may bloat in the project so much that they themselves are in shock. And remembering what was done and where is difficult. That is still a nuisance.
The version control system will help you avoid these problems. If necessary, you can restore or roll back the changes. View and confirm or cancel edits. Well, teamwork without a version control system is simply unthinkable.
')
If you don't know each other, then I want to introduce you a little bit to a version control system called Git. Under the cat you will find a description of how to use GitHub with Visual Studio.
The actual extension is called GitHub Extension for Visual Studio. It is suitable for Visual Studio 2015 and above. You can download vsix from the
github page or from the
Visual Studio gallery .
You can install the extension when installing Visual Studio:
Before continuing, you need to learn a few terms. If you know them, scroll down.
Push - sending changes from the local repository to the remote repository (in our case it will be located on GitHub).
Fetch - receiving changes from a remote repository for comparison and possible subsequent merging.
Merge - merge. Apply changes made to another repository by the current repository. Something like merging two repositories.
Pull is a combination of fetching and merging. First, a list of changes is obtained from the remote repository, and then the changes are applied to the current repository.
That is, if someone besides you worked and made changes in the GitHub repository, then you can consistently perform 2 actions: Fetch, and then Merge. Or you can immediately pull. After that, your changes will be displayed in your local repository.
After installing GitHub Extension for Visual Studio, the Team Explorer panel will look like this:
If the Team Explorer panel is hidden, you can display it through the “View” / “View” menu. Having connected to GitHub (by clicking Connect ... and entering a login with a password), we will be able to clone the GitHub repository or create a new one (the Clone and Create buttons):
During cloning, a list of repositories to which you have access will be displayed:
When creating a repository, you can enter its name, description, and select a license, according to which the use of the code is allowed:
In this case, Git ignore contains presets for projects of various types. And so this .gitignore file is intended to indicate in it which directories and files you want to exclude from the version control system.
In case you want to hide the repository very well from prying eyes, then you can mark it as Private. But for this you need a paid subscription.
For students, GitHub offers a special offer - the
Student Developer Pack , which in particular includes a free, unlimited number of private repositories.
After creating the repository, you need to create a project. Personally, I prefer the opposite, first create a project and then add it to Git. You can create a Git repository when creating a project. For this it is enough to put a tick.
If you don’t check this box when creating a project, just open the project in VS, then the “Add to Source Control” / “Add to version control system” menu will be available in the File menu.
After clicking it, the project will be added to the Git version control system, and a local .git folder will be created inside the project folder. In Team Explorer it will look like this:
Switching between Team Explorer and Solution Explorer, we can make some changes in the project. After any changes you can make a commit - a kind of recovery point. To do this, go back to Team Explorer, the menu of which has a button with a house drawn on it. Clicking on it will take you to the main menu:
The “Changes” / “Changes” button will allow you to commit the changes (it is necessary to specify a comment with a description of the changes). But all the actions so far will be done only with the local git repository.
When creating a project, sometimes a so-called “Initial commit” is created, in which something like “The project was created in three days” is written. If you have just created a project, then there are no changes in it yet. And if there are no changes, the commit cannot be created. I added a line with the text, so in the comments I tried to describe it briefly, but it is clear:
You can view the changes made. To do this, on the file you are interested in, you need to call the context menu and select "Compare with Unmodified ..." / "Compare with unchanged ..."
We get something like this:
In this case, only 2 lines of code were added. Through the same context menu, all changes that have occurred since the last commit can be undone. Very handy feature.
Now, let's go back to the main menu by clicking the house. In order to send changes to GitHub, you must click the "Sync" / "Sync" button.
Since our project has not yet been published on GitHub, we will be asked to do this:
By the way, .git is quite possible to publish not only on GitHub, but also on Visual Studio Team Services.
If we published the project earlier, then our commit will be located in the list of outgoing commits:
Pushing Push will send the changes to the repository located on the GitHub server.
Having made some changes for the sample right through the browser in the repository located on GitHub (yes, you can do that too), I went into synchronization again and pressed Fetch:
Here you can open information about the commit by double-clicking:
And already clicking on the file to view the changes:
In the same synchronization window, you can view the history:
History can be viewed in a simple view and in detail:
Now, let's imagine that we work as a team and someone else has already made some changes in their local repository and sent it to GitHub. And you also made changes in the same file and in the same line. In this case, when you synchronize with GitHub, you will have a conflict:
Clicking on Conflicts we get this window in which after clicking on the file a menu with the Merge button will open:
Now we can tick the changes we want to leave in the final version. The final version in the following screenshot is displayed below. The code in it can also be edited:
After making the change, click Accept Merge (in the upper left corner), then make a commit:
The page of the extension itself on GitHub:
github.com/github/visualstudioGithub Desktop and PowerShell environment for Git
Github Desktop is a completely independent utility and not related to Visual Studio. Download
here .
The utility is available for Mac and Windows users. Along with it, the Git Shell command line is installed. In fact, this is PowerShell with a set of scripts to integrate with Git. Called PowerShell environment for Git. Abbreviated posh-git.
On the GitHub page of the
posh-git project, you can find a brief guide on how to set the posh command line for git manually.
I will not consider the interface of the utility itself and work with it. I think that it is not difficult and you can deal with it yourself. Let's better play a little with the command line. Unlike the GUI, the command line usually provides much more features. But we will consider only the basic commands.
To view the current configuration and make sure that Git is present, you can run the command:
git config –list
In order to clone the repository, just run the
git clone command. For example:
git clone https://github.com/programmersommer/Barcode_Scanner_UWP.git BarcodeScanner
After executing this command, a folder with the project will appear in the current directory. In addition to http: // and https: //, both the SSH and git: // protocols are supported. If you switch to the project folder using the cd command (in the case of the BarcodeScanner example cd), the command line will be changed:
The PowerShell status bar displays the text
posh ~ git , which means that you are in PowerShell for Git. You can run the
git status command to find out if you need to synchronize the local repository. The answer may be:
The most popular commands are those that we have already considered as part of the VS extension interface:
git fetch ,
git merge ,
git push . If you go to the directory (the name of the PortableGit_xxx directory, I suppose, may be somewhat different):
C:\Users\{user_name}\AppData\Local\GitHub\PortableGit_284a859b0e6deba86edc624fef1e4db2aa8241a9\usr\bin
then you will find in it many executable files that emulate commands. As already mentioned, you can use git help, but let's try out a few commands for example.
For example, if a new file appears in the project directory, the git status command will display:
That means you need to add the file with the
git add index.html command. Now the changes need to be confirmed with
git commit . This command will open the default text editor. It is necessary to enter the text describing the changes made in the first line. If you start a line with a # character, this will be a comment. Comments can be left in the lines below. If you do not leave any text describing the commit, the commit will not occur. You can specify the text of the commit immediately in the command line using the –m parameter. For example:
git commit –m "File index.html added"Now you can send your changes to the GitHub repository using
git push . If this is your repository. You can copy the alien repository to yourself by creating a fork / copy of the repository - Fork. Having made some changes, you can suggest them to the author of the original repository by creating a pull request.
At this point, let me complete the description of the possibilities of working with GitHub for Windows users. If you want to continue studying, then on MVA you can watch the course
GitHub for Windows Users