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,
- Create a Git repository in Azure DevOps.
- 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
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".
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.
Once the Repository is created it will get selected by default.
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>>
Now run the below commands one after another
Step 2
cmd: git init
Step 3
cmd: git add .
Step 4
cmd: git commit -m "RELEVANT COMMIT MESSAGE"
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.
Step 6
cmd: git remote -v
If the Git is setup for the first time mean it will ask for credentials
Step 7
cmd: git push -f origin master
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.