Getting started with Azure Devops -add a repo

This is part 3 of a multipart series on getting started with Azure DevOps. Please refer to the below links to access other notes in this series.

Part 1: Getting started with Azure DevOps
Part 2: Getting started with Azure DevOps -work items
Part 3: Getting started with Azure DevOps -add a repo (this note)
Part 4: Getting started with Azure DevOps -create a build agent
Part 5: Getting started with Azure DevOps -create a build pipeline -Part 1 (YAML pipeline)
Part 6: Getting started with Azure DevOps -create a build pipeline -Part 2 (Classic Editor)
Part 7: Getting started with Azure DevOps -create a deployment group
Part 8: Getting started with Azure DevOps -create a release definition

There are three ways we can add code to our project in Azure DevOps. We could either create a new repo, upload an existing local git repo, or import one.
Whether to use TFVC or Git as a version control tool is determined when we create a project in our organization. Here is an example as I was creating a new project.
AD-GS-Repos-Image1
I proceeded with selecting Git as the version control for this project.
Once the project was created the Repos tab provided me three options to populate the repository:
-clone this empty repo to my local computer
-push an existing (local) repo that I have on my computer
-import a repository (from an external source)
AD-GS-Repos-Image2
In the notes below I walk through all the options one by one. Let’s start with Option A.
Option A: Clone to your computer.
This is by far the simplest of the approaches. Select this option if you currently have no code related to your project in any repository… as in, if this is a green-field project on which no work has started; no code exists.
Note: I had to create a separate project for this example.
There are two ways to clone this empty repository.
AD-GS-Repos-Image12
Click on the copy button and grab the URL (as shown above)
On our local, I created an empty folder where I’d want to host this repository. For e.g. C:\Git\kundusoRepo\Projects
I then opened a command prompt and pasted the command to clone the repository
git clone https://littlecoding.visualstudio.com/Project-04/_git/Project-04
As soon as I hit enter, I was requested for my Microsoft credentials.
AD-GS-Repos-Image13
After I entered them, I got a message (warning) that I cloned an empty repository. Which is true.
On my local, I just had a new folder created inside “Projects” titled Project-04 with only a .git folder.
Here is how the .config file looked
AD-GS-Repos-Image15
We’re all set after which I followed the same approach as with any git setup which is:
git add .
git commit -m ""
git pull
git push

…and after the last command, the code from our local repo would be available on the AzureDevops project repository.
Option B: Push an existing repository from the command line.
I had a windows service project that was in progress and in this example I tried to add that project to this repository. I had a couple of commits to that project on my local git instance.
On my local machine, here is my project directory.
AD-GS-Repos-Image3
The .git folder is hidden, with a config file inside. Here is the image of the contents of the file.
AD-GS-Repos-Image4
As can be seen, there is no remote URL segment, only the standard core. I then ran the git remote add origin command and captured the changes.
AD-GS-Repos-Image5
Two changes took place -the config file got updated and I was prompted for my Microsoft account login since the project I have is under my MS ID.
AD-GS-Repos-Image6
…and here is a trail of what happened after I confirmed my account.
AD-GS-Repos-Image7
…and this is how the config file looked after the above git commands were executed (note the extra remote and branch segments that got added)
AD-GS-Repos-Image8
I navigated back to our Azure DevOps project and refreshed the Repos tab. This showed the project and commit history of our project.
AD-GS-Repos-Image9
…and that is how I added a local git repo to the Azure Dev)ps instance.
Option C: Import a repository
Click on Import on the Repos landing page. We got two options:
-import a Git repository
-import from TFVC (and there are some suggestions on how to import from TFVC to Git)
AD-GS-Repos-Image16
In this example, I imported from a Github repository that I created a while back.
AD-GS-Repos-Image17
It took a few seconds to import the repository (since there was little history) and once that was done… I was able to view history on Azure DevOps project’s portal.
AD-GS-Repos-Image18
Now that I had a repository on Azure DevOps, I could clone that to my local and work off of that repository. Or if I already had cloned an empty one (as shown in Option A), I could do a git pull and get all the artifacts along with history onto my local.
AD-GS-Repos-Image19
Once I make updates (git add. -> git commit) to our local git repository it is a good idea to push to our Azure DevOps repository.
The same sequence is followed… git pull, resolve conflicts if any, git push.
These are the three options for how I was able to add code to my Azure DevOps project.

Next, Part 4: Getting started with Azure DevOps -create a build agent

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s