Part 1-Repos: "Command Your Code->Mastering Git and Azure Repos from the CLI"
Tags: git, azure, developer, devops
Published: 2023-12-06 04:00:00

Welcome back, explorers! I hope you've enjoyed the journey through Azure Boards in our previous leg of the Azure DevOps series. Now, let's dive into another crucial service—Azure Repos.

Azure Repos is your gateway to efficient version control, and we're breaking it down into two exciting segments. In Part 1, we'll empower you with command-line prowess, unraveling the secrets of Git and Azure Repos operations. It's all about commanding your code!

Then, in Part 2, get ready to visualize, collaborate, and thrive as we explore the graphical wonders of Azure Repos. From GUI magic to additional options that streamline your workflow, we've got it all covered.

Azure Repos is a version control service that enables seamless collaboration, secure code management, and comprehensive tracking of your project's history. Let's embark on this journey together—Azure Repos awaits!

=================================================================

*Note: *

When you are doing practical work, don't delete anything because our Azure DevOps series relies on continuity between each part. Ensure that you are not cleaning your workspace. Additionally, don't worry about charges, as our account is on a free trial. We are covering beginners or basic Azure DevOps, so our project is not large. If a bill is generated, it will hardly exceed 100.

=================================================================

-> So, let's get started.

-> Azure Repos supports both Git and TFVC. The difference is straightforward: Git follows a 'Distributed VCS' model, while TFVC follows a 'Centralized VCS' model.

-> Let's begin! As a first step, configure Git in VS Code. Make sure to log in to Git using your Azure email account, enabling you to seamlessly push code to Azure Repos.

-> Switch to 'Git Bash' in VS Code.

-> Configure your credentials with the following command:

```
git config --global user.name ""
git config --global user.email ""
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqfpzd3x84d4jpsbj808.png)

-> Next, open Azure DevOps and navigate to 'Parts Unlimited,' the project we configured in the last part.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ip8880pbc0mq2yi5cizm.png)

-> Then, navigate to the 'Repos' service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w6ag7ouxcfqeoarbnp0.png)

-> After opening the Repo, you will see the following window. Click on the 'Clone' option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qyayxtyo5cwcpy8kf3e.png)

-> When you click on 'Clone,' you have two options: clone the code through SSH or directly open it in an IDE. I'm using 'VS Code' as my IDE.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0w5u1qs7fbieopykpdx.png)

-> After opening it in 'VS Code,' it will prompt you to select a folder for the project. I will create one, but you can choose any folder according to your preference.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrkoia3u0vn9yyjucgy2.png)

-> When you open it, Microsoft may ask for a one-time login. In my case, it didn't ask, but if prompted, simply log in with your credentials.

-> You can see that our project has been cloned successfully.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih2voc0lgievao0k7xh9.png)

-> So, let's make some changes to the source code. I've modified one file by adding a comment. Now, we'll proceed to push or commit these changes to our 'Azure Repos.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0zq2if3a63ax0r7vr7u.png)

-> Next, click on the 'Version Control' option. You will see the 'Commit' window. Provide your commit message there and commit the changes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ulgzbu7hcrolgnd5u5zk.png)

-> Now, let's sync or push the changes to our repo. Just click on 'Sync Changes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxjo2fwys0ntedup7tqe.png)

-> Open your Azure Repos again. You will see our first commit there. Open the 'Commits' window.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf8ty6qq8qt704zysrax.png)

-> If you open that commit, you will see your changes there. Additionally, if something was added, it will be indicated with a '+' or shown in green, while deletions will show a '-' or appear in red.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hquj1zpsqk7xodipc7y.png)

-> Now, let's create another branch to perform pull requests or merging operations. Go back to VS Code, make some changes but don't commit them. In the bottom left bar, you will see the 'Branch Name.' Click on that.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k48s4kwz8f2as6qnv3vc.png)

-> Now, you will see multiple options. There are two 'master' branches: one named 'Master' representing the remote master and the other 'origin/Master' representing the remote master branch. Select 'Local Master.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz2xdfgg4zz3vzuskcbw.png)

-> Then, give a name to your branch.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eaf7pwm7t57pii2fsyww.png)

-> Check if the 'dev' branch is created and switched to.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ji1ho4quvvatwt89j42q.png)

-> Now, if you go to the 'Branches' option in Azure, you won't see the 'Dev' branch because we created it locally. Push it to the repository so that it appears there. Click on the icon below to sync.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydlahj0lk1a9u7miwvy1.png)

-> Now, go to Azure and refresh the page. You will see the 'Dev' branch, and your name will be listed there.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtjflivw4o0vi7w3id41.png)

-> Now, let's delete it. For that, click on the three dots next to this particular branch, and choose the 'Delete Branch' option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a938cg40oylw8emolriq.png)

-> Now the branch has been deleted from Azure, but if you open VS Code, it's still there.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7a0nfrorl178qq1940g.png)

-> To delete it, open the command palette with 'Ctrl + Shift + P.' Before deletion, switch to your 'Local Master' branch. Then, in the command palette, search for 'git delete branch.' You will see the 'dev' branch; click on it, and it will be deleted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4ma6glxn5ggl4vwxwh9.png)

-> But you might still see the 'origin/dev' branch, i.e., the remote branch. To remove it, you need to 'Prune' the dev branch so that unused remote branches get deleted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3pwo0p2pic1j0iyw64k3.png)

-> For that, again, use 'Ctrl + Shift + P,' search for 'git fetch (prune),

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7paorlnjpu3r5h57tfa5.png)

-> Now, check again, and you will see the branch has been deleted or removed locally.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77nvfq6fc5sx5knd0slp.png)

=================================================================

**Summary:**

In this session, we configured Git in VS Code, cloned the project to Azure Repos, made changes, and even explored branch creation and deletion. For our next blog, get ready to delve into the visual wonders of Azure Repos GUI, where we'll enhance collaboration and streamline workflows. Stay tuned for a GUI extravaganza in Part 2!

=================================================================

If you have any doubts, questions, or recommendations, feel free to drop a comment. Follow me for updates and happy learning! :)