Create A New Git Repo And Add Existing Code To Azure DevOps

In this blog, we're going to see how to create a git repository in Azure DevOps and add existing code into that repository.

Introduction

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 and add your existing source code into git repository using command prompt

I am going to divide this session into two parts,

  1. Create a Git repository in Azure DevOps.
  2. Add your code to the Git repository

I) Create a Git repository in Azure DevOps

Step 1

Open DevOps and choose the respective project.

Click on Repos

Create a Git repository in Azure DevOps

Step 2

From Repos click on Files and click on the repositories which is already there, in my case it is "Internal".  From the dropdown click on "New repository".

Create a Git repository in Azure DevOps

Step 3

A panel will appear in that Choose Repository type as Git.

Give Repository Name as per requirement, in my case I have given as "Test Repository".

You can uncheck Add a README checkbox, Normally it will add a readme.txt file in the repository if it is checked.

After that click on Create button.

Create a Git repository in Azure DevOps

Once the Repository is created it will get selected by default.

Create a Git repository in Azure DevOps

II) Add your code to the Git repository

Step 1

Now open a command prompt and locate your file location by giving cd <<File Location>>

Add your code to the Git repository

Now run the below commands one after another 

Step 2

cmd: git init

Add your code to the Git repository

Step 3

cmd: git add .

Add your code to the Git repository

Step 4

cmd: git commit -m "RELEVANT COMMIT MESSAGE"

Add your code to the Git repository

Step 5

cmd: git remote add origin <Git Repository URL>

To get the Git Repository URL open the newly created repository and copy the URL. 

Add your code to the Git repository

Add your code to the Git repository

Step 6

cmd: git remote -v

Add your code to the Git repository

If the Git is setup for the first time mean it will ask for credentials

Add your code to the Git repository 

Step 7

cmd: git push -f origin master

Add your code to the Git repository

If everything went correctly  we will see the message as above.

Commands which are used to add code to Repository

git init

git add .

git commit -m "RELEVANT COMMIT MESSAGE"

git remote add origin <Git Repository URL>

git remote -v

git push -f origin master

Conclusion 

In this blog, we have seen how to add the existing code to the Azure Devops using command prompt.

Leave a command if there's an issue.

Catch you all in a new blog.