Create a new Git repo in your project

Azure Repos | TFS 2018 | TFS 2017 | TFS 2015

Azure DevOps Services and TFS projects contain Git repositories, work items, builds, and releases. You can use Git repos in your projects to manage your source code as your project grows. This guide shows you how to create a Git repo using the web portal for either Azure DevOps Services (hosted on Azure) or Team Foundation Server (TFS - on-premises).

Prerequisites

Create a repo using the web portal

Note

Your web portal uses either the New navigation or Previous navigation user interface. Choose the New navigation tab if the New Navigation feature is enabled. You'll see a vertical sidebar along with other navigational features when New Navigation has been enabled for the signed-in user or the organization. Choose Previous navigation when you see a top-level, blue-bar—indicating that New navigation isn't enabled. For more information, see Web portal navigation.

Note

Choose the New navigation tab for guidance. Azure DevOps Server 2019 supports the New Navigation user interface. For more information, see Web portal navigation.

Note

Choose the Previous navigation tab for guidance. TFS 2018 and earlier versions only support the previous navigation user interface. For more information, see Web portal navigation.

  1. Navigate to the Repos page in your project by browsing to https://<your account name>.visualstudio.com, hovering your mouse over the name of your project, and selecting the Repos icon. You can select it from the All projects list, or from the Recent projects list if you have accessed it recently.

    Select project

  2. From the repo drop-down, select New repository.

    Manage repositories

  3. In the Create a new repository dialog, verify that Git is the repo type and enter a name for your new repo. You can also choose to add a README and create a .gitignore for the type of code you plan to manage in the repo. A README contains information about the code in your repo, and a .gitignore file tells Git which types of files to ignore, such as temporary build files from your development environment.

    Set options for your new repo in the Create a Git repo dialog

  4. When you're happy with the repo name and choices, select Create.

    A new empty Git repo is now created in your project.

    • If you created an empty repo (no README or .gitignore), you'll see instructions on how to clone the repo to your computer or push code in an existing repo into the newly created one.
    • In this example you created a README and a .gitignore, so you'll see an overview of the files in your repo, and you can clone the repo using the Clone link on the upper right of the page to get working with a local copy of the repo immediately.

Select Previous navigation to view the steps for this procedure in your selected version of the documentation.

Clone the repo to your computer

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.

Note

Your web portal uses either the New navigation or Previous navigation user interface. Choose the New navigation tab if the New Navigation feature is enabled. You'll see a vertical sidebar along with other navigational features when New Navigation has been enabled for the signed-in user or the organization. Choose Previous navigation when you see a top-level, blue-bar—indicating that New navigation isn't enabled. For more information, see Web portal navigation.

Note

Choose the New navigation tab for guidance. Azure DevOps Server 2019 supports the New Navigation user interface. For more information, see Web portal navigation.

Note

Choose the Previous navigation tab for guidance. TFS 2018 and earlier versions only support the previous navigation user interface. For more information, see Web portal navigation.

  1. From your web browser, open the team project for your organization in Azure DevOps and select Repos > Files. If you don't have a team project, create one now.

    Repos files

  2. Select Clone in the upper-right corner of the Files window and copy the clone URL.

    Retrieve the clone URL

  3. Open the Git command window (Git Bash on Git for Windows) and browse to the folder where you want the code from the repo stored on your computer. Run git clone followed by the path copied from the Clone URL in the previous section, as shown in the following example.

    git clone https://dev.azure.com/fabrikam-fiber/MyFirstProject/_git/
    

    Git downloads a copy of the code, including all commits and branches from the repo, into a new folder for you to work with.

  4. Switch your directory to the repository that you cloned.

    cd fabrikam-fiber
    

    Keep this command window open, because 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.

  1. Browse to the folder on your computer where you cloned the repo and open the README.md file in your editor of choice.

  2. Make some changes, for example add This is my first edit. to the file, and save and close the file.

  3. In the Git command window, navigate to the fabrikam-fiber directory by entering the following command:

    cd fabrikam-fiber
    
  4. Commit your changes by entering the following command in the Git command window:

    git commit -a -m "My first commit"
    

    When using git commit, -a means to commit all changed files, and -m specifies a commit message.

  5. Push your changes up to the Git repo on the server by entering the following command into the Git command window:

    git push
    
  6. 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.

    View commit history

  7. Switch to the Files tab and click on the README file to view your changes.

    View changed file

Next steps