Git in Visual Studio - add an existing project?

I am trying to put an existing project under the control of the Git source code, but a few things are not clear to me.

I created a Git "Team Foundation Service" account on the Internet.

I currently have an ASP.NET MVC 4 solution - in my Projects folder. I created Git 'repository' locally (currently this is an empty folder). Should this be my current application folder in Projects? Or should it be a copy?

How can I get my existing files in online storage?

+75
git tfs visual-studio-2008 visual-studio-2012 vsts azure-devops
May 29 '13 at 22:30
source share
15 answers

I was looking for a similar question - I was able to initialize the Git repository for an existing project file (disclaimer: this is done in Visual Studio 2013 Express without installing Team Foundation Server):

  1. Open the project in Visual Studio.
  2. Go to File → Add to Version Control System.

This did it for me - assuming Git is configured for you, you can go to the View → Team Explorer menu, then double-click on the repository for your project file and perform the initial commit (making sure that you have added any files you want).

+100
Nov 23 '13 at 21:45
source share
  1. First of all, you need to install Git software on your local development machine, such as Git Extensions .
  2. Then do git init in the solution folder. This is the correct way to create a storage folder.
  3. Set up a reasonable .gitignore file .gitignore that there are no .gitignore unnecessary things.
  4. git add
  5. git commit
  6. Add the appropriate remote as described in your Team Foundation Server account git remote add origin <proper URL>
  7. git push your code

In addition, there are detailed tutorials here using Visual Studio integration.

+59
May 30 '13 at 5:45
source share

After scrolling around Visual Studio, I finally found an answer that took a lot longer than it should.

To take an existing project without source control and put it into the existing GitHub repository (this is important), this process is simple but complicated, since your first desire is to use Team Explorer, which is wrong, and therefore you have problems

First add it to the version control system. There are several explanations for this above, and each goes so far.

Now it opens an empty LOCAL repository, and a trick that no one ever talks about is to completely ignore Team Explorer and go to Solution Explorer, right-click on the solution and click Commit.

Then it captures all the differences between your existing solution and local storage, essentially updating it with all these new files. Give it the default commit name 'source files' or something else that floats on your boat and commits.

Then just click “Sync” on the next screen and paste in the EMPTY GitHub URL. Make sure that it is empty, otherwise you will have conflicts of the main branches, and it will not allow you. So either use the new repository or delete the old one that you messed up earlier. Keep in mind that this is Visual Studio 2013, so mileage may vary.

+13
Jun 19 '15 at 20:18
source share

Just right-click on your solution and select Add to Version Control System. Then select Git.

Now your projects have been added to the local control source. Right-click on one of your files and select "Apply."

Then enter the commit message and select Commit. Then select Sync to sync your project with GitHub. Git repository required. Go to GitHub, create a new repository, copy the link to the repository and add it to your remote source control server. Choose Publish.

All this.

+12
Apr 05 '14 at 15:50
source share

Using SourceTree :

Right-click the name of the solution in Solution Explorer. Select Add to Version Control.

Then go to SourceTree and select Clone / New. Select "Add working folder" and specify the new Git location that you just created in your solution.

Go and take the clone address for the empty Git (Bitbucket or GitHub) and go back to SourceTree, right-click Remotes and add New Remote. (Note that in modern versions go to Vaults → Add Remote ... Paste your URL in this field and click OK .

Here's how you can make your initial commit and push.

+4
Feb 20 '15 at 14:28
source share

In Visual Studio 2015, the only way I was finally able to run it was to run git init from the root of my directory using the command line. Then I went into Team Explorer and added the local git repository. Then I selected the local git repository, went to Settings-> Repository Settings and added my remote repo. Here is how I was finally able to integrate Visual Studio to use my existing project with git.

I read all the answers, but none of them worked for me. I went to File-> Add To Source Control, which suggested that it would basically do the same as git init , but it didn't seem to initialize my project, because when I go to Team Explorer, all the options were grayed out, Also nothing was found in the change dialog. Another answer stated that I just needed to create a local repo in Team Explorer, and then my changes would appear, but that didn't work either. All git options in Team Explorer worked only after I initialized the project through the command line.

I am new to Visual Studio, so I don’t know if I missed something obvious, but it looks like my project was not initialized from Visual Studio.

+3
Feb 01 '17 at 18:19
source share

First create a "Solution Folder" with the desired relative path. Please note that Visual Studio 2012 does not create a system folder with the same relative path.

Now add a new project inside this “Solution Folder”, but when defining it, you must be careful that the relative path in the system matches the relative path of your new “Solution Folder”. If the desired system folder does not exist, Visual Studio 2012 will create it for the new project. (As noted above, this does not happen when adding a new “Solution Folder”.)

If you want to add an existing file with the corresponding relative path, you must first create the file in the corresponding system relative path from outside Visual Studio. You can then add the existing file in Visual Studio.

+2
Aug 02 '13 at 17:20
source share

If the desired repository already exists (possibly on GitHub), you can clone it into your local system and then copy the solution directory to it. Then add files, commit files and send local ones. This put the solution in storage.

+1
Jun 24 '14 at 15:40
source share

Obviously, the easiest way is described in the MSDN article. Share your code with Visual Studio 2017 and VSTS Git .

  1. Create a new local Git repository for your project by selecting Add to Source Control in the status bar in the lower right corner of Visual Studio. This will create a new repository in the folder where the solution is located and put your code into this repository.

    Enter image description here

  2. In the Push view in Team Explorer, select the "Publish Git Repository" button in the "Push to Visual Studio Team Services" section.

    Enter image description here

  3. Connect Remote Source Control, enter the name of your repository, and select Publish Repository.

    Enter image description here

+1
Aug 30 '17 at 13:44 on
source share

If you want to open an existing project from GitHub, you need to do the following (these are steps only for Visual Studio 2013 !!!! And newer, since there is no built-in Git installation in older versions):

  1. Team explorer -> Connect to teamProjects -> Local GitRepositories -> Clone.

  2. Copy / paste your GitHub address from the browser.

  3. Select a local path for this project.

0
Mar 19 '15 at 14:34
source share

For me, a Git repository (not GitHub) has already been created, but empty. This was my solution to add an existing project to the Git repository:

  1. I cloned and checked the repository with Git Extensions.
  2. Then I copied my existing project files to this repository.
  3. Added .gitignore file.
  4. Delivered and transferred all the files.
  5. Pushed to a remote repository.

It would be interesting to see how all this is done directly in Visual Studio 2015 without tools such as Git Extensions, but what I tried in Visual Studio did not work (Add to source control system is not available for my project, there was no remote help, etc.).

0
Aug 09 '16 at 9:43
source share

Git in Visual Studio - add an existing project ; How to publish your local repository in a project on GitHub, GitLab or the like.

So you created the solution, and you want it to download and control the version through your Git account. For this, in Visual Studio 2015 there are tools in Team Explorer.

As Meuep mentions, download your solution, and then go to File >> Add to Source Control . This is the equivalent of git init . Then you will have this:

Team Explorer Home

Now select " Settings >>" Settings Repository Settings and go to "Deleted".

Enter image description here

Set origin (make sure you put this reserved name there) and set the URI.

Then you can use Add , Sync and Publish .

0
Nov 08 '16 at 23:46
source share

To add a project to the solution, simply open the Team Explorer window and go to the "Changes" section. Then, in the Untracked Files section, click View Options and select Switch to Tree View (if it is not in the tree view), right-click the project root folder and select Add.

Enter image description here

0
Nov 28 '16 at 3:38
source share

I always forget this, so this is more for me, but maybe it can help someone else using VS.

Visual Studio has a concept of solutions. However, git has the concept of a git repository tracked by local and remote branches. All files and folders that are added to git are local.

Now returning to Visual Studio solutions, when you create a standard template project, it creates all projects locally for this solution.

So the problem arises when you add a project that is not local to the solution or git in this regard. The following happens: the .sln solution file is updated according to the project location, but the actual project contents, project files and folders cannot be added to git, because they are located in a separate directory, on a separate network drive, or on some kind of FTP server. etc ..... This may be preferable if you only need a link to a project file that compiles only in the .sln file, or you want to use them as a source for individual git or github repositories. But you do not want real files to be tracked by Git locally.

To fix this (i.e. you want to add them to your git repository), you simply move the deleted files of interest within the solution and its project files so that they are local.

0
Jan 09 '19 at 19:41
source share

The process is greatly simplified for VS2017 / VS2019 (perhaps even earlier, but I have not tested it) in conjunction with GitHub:

  1. Create an empty repository in GitHub => https://github.com/ /.git

  2. Install the GitHub extension for Visual Studio

  3. Follow these instructions : (if desired, add git to the source control system) → Team explorer → Sync → Publish to GitHub → https://github.com/ /.git

0
Feb 02 '19 at 18:34
source share



All Articles