Code with Git
After you create a new account and team project in VSTS, you can begin sharing your code with others.
To work with a Git repo, you clone it to your computer. Cloning a repo creates a complete local copy of the repo for you to work with, and downloads all commits and branches in the repo and sets up a named relationship with the repo on the server. Use this relationship to interact with the existing repo, pushing and pulling changes to share code with your team.
Install Git command line tools
Install one of the following Git command line tools:
- To install Git for Windows, including Git Credential Manager, see Install the Git Credential Manager - Windows
- To install Git for macOS and Linux, see Install the Git Credential Manager - macOS and Linix
Clone the repo to your computer
From your web browser, open the team project for your VSTS account and click the Code hub. If you don't have a team project, create one now.
Select Clone in the upper-right corner of the Code window and copy the Clone URL.
Open the Git command window (Git Bash on Git for Windows), navigate to the folder where you want the code from the repo stored on your computer, and run
git clonefollowed by the path copied from the Clone URL in the previous step, as shown in the following example.
git clone https://contoso-ltd.visualstudio.com/MyFirstProject/_git/contoso-demo
Keep this command window open, as you'll use it in the following steps.
Work with the code
In this step, we'll make a change to the files on your computer, commit the changes locally, push the commit up to the repo that is stored on the server, and view the changes there.
Browse to the folder on your computer where you cloned the repo, open the
README.mdfile in your editor of choice, make some changes, and save and close the file.
In the Git command window, navigate to the
contoso-demodirectory by entering the following command:
Commit your changes by entering the following command in the Git command window:
git commit -a -m "My first commit"
-ameans to commit all changed files, and
-mspecifies a commit message.
Push your changes up to the Git repo on the server by entering the following command into the Git command window:
Switch back to the web portal and select History from the Code view to view your new commit. The new repo has two commits: the first commit where the README and .gitignore were added when the repo was created, and the commit you just made.
Switch to the Files tab and click on the README file to view your changes.