Use the Git command prompt to supplement Visual Studio

MSDNBlogAdmin

//

By: Andy Lewis and Matthew Mitrik

In Visual Studio Tools for Git we aim to offer the fundamental features you need to develop an app in a Git version-controlled codebase. We explain how to perform these tasks in previous posts such as Create, Connect, and Publish using Visual Studio with Git and in our Git welcome portal content.

That said, there is a long tail of less-common tasks in software development work. If you can’t yet do what you want to do in VS, you might be able to do it from the command prompt. Also, many developers find the command prompt to be a handy and efficient way to perform repetitive tasks, either manually or with a script.

Got the latest version of Visual Studio with Git? If not, click here.

Get set up to use the command prompt tools

Enable basic authentication for your TFS account

If your repo is hosted in Team Foundation Service (TFS), then you must enable basic authentication before you can use the command prompt to fetch, pull, push, clone, etc. You can set this up from your User Profile in TFS. Show me.

Tip: To make using the command prompt less tedious (for example, to avoid having to enter your credentials every time you push), you might want to also install Windows Credential Store for Git on your dev machine.

Get the command prompt tools

If you have not already installed some command-prompt tools, you can get some quickly from Visual Studio. (One way you can tell that you don’t have the tools is if you try to enter a git command and get the ‘git’ is not recognized as an internal or external command… message.) Go to the Settings page and click Install 3rd-party tools. Show me.

Tip: The install process drops a Git Bash icon on your desktop. You can delete this icon; we don’t believe this entry point leads to the best experience. And anyway, you can still get to it from Windows Start if for some reason you need it later.

Open the Git command prompt window

You can open the command prompt from the Actions menu on the Changes, Commits, and Branches pages. You can also open it from the Connect page: Right-click your local repo, and then click Open Command Prompt. Show me.

Work from the command prompt

We hope you find the following table to be a useful if not complete guide to some of the more common tasks. You can find more command-prompt reference information here: http://git-scm.com/docs.

Caution: If you are not an experienced Git user, use the command-prompt carefully. Make sure to research the command thoroughly before you use it.

Task Visual Studio Command Prompt

Create a local repository

Yes git-init

Copy a remote repository to your dev machine

Yes git-clone

Fetch and pull changes from a remote repository

Yes (some conflicts can be resolved only at command prompt) git-fetch, git-pull

Get information about a repository

You can if it is in a TFS team project (shown in bold text and with hover info in Team Explorer) git-remote

Commit your changes

Yes git-commit

Amend your last commit. Some typical cases:

No git-commit

Undo a committed change by applying the inverse of the commit. See rolling back changes with revert.

No git-revert

Undo committed changes by returning your local repo to a prior commit and de-referencing the later commit.  See Undoing Things, which warns, “…this is a dangerous command: any changes you made to that file are gone — you just copied another file over it. Don’t ever use this command unless you absolutely know that you don’t want the file.”

No git-reset

Branch and merge

Yes (some conflicts can be resolved only at command prompt). (We plan to post more info on branches. For now, see our announcement post.) git-branch, git-merge

Re-order history or combine commits. See Git Branching – Rebasing.

No git-rebase

Push changes to a remote repository

Yes git-push

<!–

Use the Git command prompt to supplement Visual Studio

–>

0 comments

Discussion is closed.

Feedback usabilla icon