Part 1: Configuring Git Client and Managing Branches in Azure DevOps

Part 1: Configuring Git Client and Managing Branches in Azure DevOps

In this post, we’ll walk through the process of configuring a Git client using VS Code and managing branches in Azure DevOps. This will cover everything from setting up credentials to committing changes and syncing branches with a remote repository.

Step 1: Configure Git Client

To begin, we’ll configure VS Code as our Git client, but feel free to use any other Git client you prefer.

  1. Open VS Code.

  2. Go to the terminal and open a new terminal.

  3. Switch the terminal to Git Bash.

  4. Run the following command to save your credentials:

     git config --global credential.helper wincred
    
  5. Set up your username and email for Git:

     git config --global user.name "Your Name"
     git config --global user.email "your-email@example.com"
    

Step 2: Clone a Repository from Azure DevOps

  1. Log into Azure DevOps and navigate to your project (e.g., Parts Unlimited).

  2. Go to Repos on the left-hand menu and click Clone.

  3. You can either generate Git credentials or copy the repository URL.

  4. Select Clone in VS Code from the dropdown, and it will prompt you to open VS Code.

  5. Choose or create a new folder in VS Code to clone the repository into.

  6. If prompted, log into your Microsoft account to authenticate.

Once authenticated, your credentials will be saved, so this step is a one-time process. After cloning, the entire project will be visible in VS Code.

Step 3: Making Changes and Committing

Let’s make a small change in the code:

  1. Open a file, for example, from the Migration folder.

  2. Add a comment (e.g., // First change), and save the file using Ctrl + S.

  3. You will see the change in the Source Control tab, but it's still not committed to the remote repository.

To commit the change:

  1. Add a commit message, like "My first change."

  2. Click Commit to save it locally.

  3. Click Sync Changes to push your changes to the remote repository.

You can now view the commit history in Azure DevOps under Commits, where you will see the latest commit.

Step 4: Staging and Committing Specific Changes

Let’s explore how to stage specific changes:

  1. Make changes to two files and save them.

  2. In Source Control, click the + symbol next to one of the files to stage that change.

  3. Add a commit message (e.g., "Change 2") and commit the staged file only.

  4. Now, sync the changes to the remote repository.

The staged changes will be pushed, but the unstaged file will remain as a local change.

Step 5: Understanding Branches

Branches allow you to work on different versions of your codebase without affecting the main code. When you clone a repository, a local branch (usually master) is created. The changes made on this branch are synced to the remote master branch.

To create a new branch (e.g., dev) in VS Code:

  1. Click on master at the bottom left of the screen.

  2. Select Create new branch from master.

  3. Name the branch dev, and hit Enter.

Now, any changes made will be on the dev branch.

Step 6: Syncing and Deleting Branches

To sync the branches:

  1. Click Sync Changes, and the new dev branch will also be synced to the remote repository.

  2. You can view the new branch under Branches in Azure DevOps.

To delete the remote branch:

  1. Go to the three dots next to the branch in Azure DevOps and click Delete Branch.

  2. In VS Code, run Ctrl + Shift + P, type Git: Delete Branch, and select the local dev branch to delete.

Lastly, to remove the unused remote branch:

  1. Run the command Ctrl + Shift + P and type Git Fetch Prune. This will fetch and remove any deleted remote branches locally.

Check the output logs to track what changes were made.
Stay tuned for Part 2, where we’ll cover how to manage branches and pull requests directly from Azure Repos

Part 2: Managing Branches and Pull Requests in Azure DevOps