3 out of 5 rated this helpful - Rate this topic

Develop your app in a Git repository (track, commit)

Visual Studio 2013

As you write your code, you can see, modify, and, as necessary, undo your changes. Commit as early and as often as you like. All your commits are local until you push them, so no Internet access is required.

To begin working in a Git repository, open it from the Team Explorer Connect page (Keyboard: Ctrl + 0, C).

Hover over a Git team project to get information

The Team Explorer Connect page shows a list of repositories. Your repositories that have been published to Team Foundation Server (TFS are listed first. At the bottom of the page are the repositories that have not been published to TFS, including those with remotes hosted on other services such as CodePlex or GitHub.

From the Team Explorer Home page (Keyboard: Press Ctrl + 0, H), start coding in a new or in an existing solution.

Open a solution from the Team Explorer Home page

After you open you solution, open Solution Explorer (Keyboard: Ctrl + Alt + L).

You can see what you've changed as you write code
  1. If you’re working in a solution that contains a lot of files, you’ll probably find it convenient to filter Solution Explorer to show only the files you have changed Changes filter (Keyboard: Ctrl + [, P).

  2. You can see changes you’ve made since the last commit, and if you want, you can continue to write code in the Diff window.

  3. To see past changes, choose View History. To back out the changes you have made since the last commit, choose Undo. See View and manage past versions in Git

  4. To open the Changes page with only those files in the Included section, select one or more files and choose Commit.

When you open and modify a file from Solution Explorer, the file is automatically checked out for you. Icons appear to indicate which files you have not changed TFSC Checked-In Status Icon, those you have checked out TFSC Checked-Out Status Icon, and those you have added to the solution TFSC Pending Addition Status Icon.

In most cases, you use Solution Explorer to add, rename, and delete items. In some cases, you might need to work with files that are not part of a solution.

Open in File Explorer from the Changes page

File Explorer

For example, you could add a file, like the one in the illustration, to the Git repository on your dev machine.

Untracked Fiiles on Changes page

Add change in Included Changes on Changes page
Tip Tip

As you develop your app in Solution Explorer, additions, edits, renames, and deletions are automatically tracked for you. But when you need to manage and eventually commit the changes you’ve made in your workspace, you can do it from the Changes page in Team Explorer (Keyboard Ctrl + 0, G).

Git Changes page

Related Work Items: Add tasks here to help you identify your work. After you commit your changes, your team can view the related work items and see exactly which code changed to complete each task.

Use the controls on the page to associate work items. You can also associate work items by specifying them in your comment. For example you could associate the comment Add greeting #1 either on the Changes page or when using the git-commit command from the command prompt.

The association with the commit takes effect after you push.

Included and Excluded changes: Use these lists to control whether or not a change is included when you commit. If you want to:

  • See details about what you’ve changed, right-click the file and choose Compare with unmodified.

  • Undo your changes, right-click it the file and choose Undo.

Commit: You can commit your changes as often as you like. Your commits are stored on your local dev machine until you are ready to push them.

If you need to modify your last commit (for example, to change the comment or add a file), choose Actions and then choose Amend Previous Commit. See also: How do I alter or undo my committed changes?

Untracked Files: Lists files that are not in the repository and not ignored. In most cases you should move any item listed here into Included Changes. If the item is a transient file that you need but don’t want to add to the repository, you can ignore it.

Modify the view: To view your changes in a separate window, Undock Undock from Team Explorer. You can also toggle between list view and tree view from the Actions menu.

Most developers use a .gitignore file to avoid cluttering their working environment and repository with temporary files such as locally compiled binary files. When ignored files or folders are added (for example, when Visual Studio locally builds your .dll files) to a folder in your local Git repository, they do not appear in the Changes page in Team Explorer, and these files are not committed or pushed.

In most cases, you can use the default .gitignore file provided by Visual Studio without customization. If you don’t have a .gitignore file, you should add one. Make sure you are connected to a local or remote Git repository. Then open the Git Settings page.

Opening the Git Settings page

Adding Git repository setting files

One simple way to ignore a file, a type of file, or even a folder, is to do it from the Changes page:

Ignoring files from Git Changes

You can also directly edit your .gitignore file from Git Settings:

Editing Git repository settings

The effects of the .gitignore file are recursive. You can create .gitignore files in sub-folders to override the effects of a .gitignore file in a parent folder. For details about .gitignore files, including their syntax, see Ignoring files and gitignore(5) Manual Page.

In most cases, you should commit and push your .gitignore file so that everyone else on your team uses the same repository settings on their dev machines.

A: You have a couple of options:

A: If the commit is the latest and only commit on your dev machine, you can amend it from the Changes page (choose Actions and choose Amend Previous Commit). Otherwise, after you have pushed the commit, open the work item in your web browser (Keyboard: Ctrl + 0, A), and link to the commit from there.

A: If you are an experienced Git user, you might have noticed that Visual Studio handles changes differently than the command prompt. You might have wondered if the Included Changes section contains your staged changes. In fact, Visual Studio usually bypasses the Git stage for you. When you commit changes, Visual Studio simultaneously stages and commits them. The one exception occurs when you add a file to your Git repository; Visual Studio does stage this kind of change.

A: Unlike TFVC, in a Git repository, you cannot commit an empty folder.

A: In most cases, the author and the committer of a commit are the same person. One situation in which they differ is a commit that has been rebased. For example, if Julia rebases a commit from Peter, she becomes the committer of that commit, but Peter is still the author of the commit.

A: In general, you should avoid adding binary files to your Git repository, especially large ones that you change a lot. In many cases, you can use NuGet to dynamically download these kinds of dependencies. See NuGet.

Are you ready to contribute your changes to the team and finalize the process to associate work items with your commits? See Collaborate in a Git team project (pull, push).

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.