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.
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)
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.
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.
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
We’re all set after which I followed the same approach as with any git setup which is:
git add .
git commit -m ""
…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.
The .git folder is hidden, with a config file inside. Here is the image of the contents of the file.
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.
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.
…and here is a trail of what happened after I confirmed my account.
…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)
I navigated back to our Azure DevOps project and refreshed the Repos tab. This showed the project and commit history of our project.
…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)
In this example, I imported from a Github repository that I created a while back.
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.
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.
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