Sie sind auf Seite 1von 17

06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

Get Started with Git and VSTS


 14/03/2018 •  7 minutos para ler

Neste artigo
Get your code
Commit your work
Share your changes
Sync with others

Visual Studio 2017

VSTS | TFS 2018 | TFS 2017 | TFS 2015 | VS 2017

This guide covers the basics so you can get up and running using Git with code already in Visual Studio
Team Services (VSTS) or Team Foundation Server (TFS). Explore our full tutorial for more information on
how to use Git from Visual Studio or the command line.

If you don't have your code in a VSTS or TFS Git repo, visit our Visual Studio or command line getting
started articles to learn how to create a local repo for your code and push it to VSTS.

Get your code


To get a copy of the source code, you clone a VSTS Git repository. Cloning creates both a copy of the
source code for you to work with and all the version control information so Git can manage the source
code.

If you don't have a Git repository yet, you can create one using your own code and continue with the
steps in this article to commit and share your work.
https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 1/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

Visual Studio Command Line

1. In Team Explorer, open up the Connect page by selecting the Connect icon, and then
choose Manage Connections, Connect to Project.

2. On the Connect to a Project dialog, select the repo you want to clone from the list and
select Clone. If you don't see your repo listed, you can filter the list to find it or add a
Team Foundation Server where the repo is hosted by selecting the Add TFS Server link.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 2/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

3. Verify the location of the cloned repo on your PC and select Clone.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 3/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

Commit your work


Git branches isolate your changes from other work being done in the project. The recommended Git
workflow uses a new branch for every feature or fix you work on. You make commits in your local Git
repository to save your changes on that branch.

Visual Studio Command Line

1. In Team Explorer, select the Home icon and choose Branches.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 4/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

2. Right click the master branch and choose New Local Branch From...

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 5/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 6/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

3. Choose a descriptive branch name for your work to remind you and others what kind of
work is in the branch, and select Create Branch.

4. Make changes to your files in the cloned repo. From the Team Explorer Home view, you
can open up Visual Studio solutions in the repo or browse the repo contents using the
Show Folder View link. Git keeps track of changes made to your code both inside and
outside of Visual Studio.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 7/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

5. When you are satisfied with the changes, save them in Git using a commit. Open up the
Changes view from Team Explorer by selecting the Home icon and choosing Changes.

6. Enter a message describing the commit, and select Commit All.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 8/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

 Note

If you have multiple files and you don't want to commit them all, you can right-click
each desired file and choose Stage. When you have staged all the files you would
like to commit, click Commit Staged. (The Commit All button is replaced by
Commit Staged when you manually stage your changes before the commit.)
https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 9/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

Share your changes


When you are ready to share your changes with the team, you can push those changes so that others
can reach them. You can only push changes after you add commits to a branch.

Once you push the changes, you can create a pull request to let others know you'd like to have the
changes reviewed and added to the master branch of the code.

Visual Studio Command Line

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 10/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

1. Open up the Synchronization view in Team Explorer by selecting the Home icon and
choosing Sync.

You can also navigate to the Synchronization view from the Changes view by choosing
Sync immediately after making a commit.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 11/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

2. Select Push to share your commit with the remote repository.

If this is your first push to the repository you'll see the following message in place of the
outgoing commits list:

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 12/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

The current branch does not track a remote branch. Push your changes to a new branch on
the origin remote and set the upstream branch.

Select Push to push your changes to a new branch on the remote repository and set the
upstream branch. The next time you push changes you'll see the list of commits.

3. Create a pull request so that others can review your changes. Open Pull Requests in
Team Explorer by selecting the Home icon and choosing Pull Requests.

4. From the Pull Requests view you can view pull requests opened by you, assigned to you,
and you can create new pull requests. Select New Pull Request to open up a web

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 13/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

browser where you can create the new pull request in the VSTS web portal.

5. Verify your branches (in this example we want to merge the commits from the ReadMeFix
branch into the master branch), enter a title and optional description, specify any
reviewers, optionally associate any work items, and select Create.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 14/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

For more information on pull requests, see the pull request tutorial.

Sync with others


To get changes from others and keep your code up to date, you can pull commits made by others and
merge them into your branch. Git is very good about merging multiple changes even in the same file,
https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 15/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

but sometimes you might have to resolve a merge conflict. It's a good idea to pull your branches
regularly to keep them up to date with the changes from others. This makes sure that your feature
branches from your main branch are using the latest version of the code.

Visual Studio Command Line

1. Open up the Synchronization view in Team Explorer by selecting the Home icon and
choosing Sync.

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 16/17
06/04/2018 Get started with Git and Visual Studio 2017 | Microsoft Docs

2. You can download the latest changes to the branch you are on using the Pull link. (There
are two Pull links, one near the top and one in the Incoming Commits section. You can
use either one as they both do the same thing.)

https://docs.microsoft.com/pt-pt/vsts/git/gitquickstart?view=vsts&tabs=visual-studio 17/17

Das könnte Ihnen auch gefallen