Skip to content

DevOps for the Terrified

Terrified Photo by Simon Migaj on Unsplash

I've been preparing some videos and learning materials for colleagues that work in Cloud but don't come from a Software Engineering background where disciplines such as version control and continuous integration are taken as granted.

Preparing your machine

Install the most common extensions you might need. This is using a tool called Scoop which I've talked about before.

Open Powershell and run this:

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('')
scoop bucket add extras
scoop install sudo aria2
scoop install git posh-git
scoop install vscode windows-terminal

Install extensions for VSCode

These are the extensions you'll probably need, you can add any VSCode tends to prompt you for any others you may need when you work with a new file type that it recognises is associated with an one or more suggested extensions

code --install-extension
code --install-extension
code --install-extension ms-vscode.azurecli
code --install-extension ms-vscode.powershell
code --install-extension msazurermtools.azurerm-vscode-tools

Use Git for Version Control

Set some default configuration

git config --system core.longpaths true
And enable long paths (see: Enable Long Paths in Windows)

Tell Git who you are (used as the author name/email when you issue the git commit command):

# default details used for all repositories (if not over-ridden by a local config)
git config --global 'Your Name'
git config --global '[email protected]'
# details used for the current repository (i.e over-riding any global config)
git config --local 'Your Name'
git config --local '[email protected]'
What if I forget?

If you forget to set your email you get a pretty helpful error message like this:

Author identity unknown

*** Please tell me who you are.


  git config --global "[email protected]"
  git config --global "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address

Start work on an existing Repository

Get the Git Clone URL from a repository you want to work on:

Clone URL - Azure DevOps

Open VSCode

then in VS Code Ctrl-Shift-P and then type 'git clone'

Change directory into the new directory that gets created after you have cloned the Repository

Using different repositories with different credentials

If you commit to different repositories with different credentials then you will need to give Git some configuration info about yourself as explained above

git config --local 'Your Name'
git config --local '[email protected]'

Create a branch to work on

Use the branch command to create the branch and checkout to swap to that branch.

git branch feature/TryingSomething
git checkout feature/TryingSomething

Once you have edited or added some files you need to push you changes (but it's important to update your branch with changes in the trunk to avoid later merge conflicts when making a Pull Request]):

git add .
git commit -m 'my commit message'
# merge the latest changes from main into the feature branch
git pull origin main
git push --set-upstream origin feature/TryingSomething
Why not just use git push?

i.e. what's the --set-upstream about? You'll get an error if you just use git push because the remote branch doesn't yet exist):

fatal: The current branch feature/TryingSomething has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin feature/TryingSomething

Create and merge a Pull Request

Open up your Repository in Azure DevOps or GitHub and create a pull request:

Create Pull Request

If all goes well your Pull Request will get approved and merged and you no longer need your local branch for this feature (the remote branch will have been deleted and you need to clean up your working directory).

Merge Pull Request

Deleting your branch

You no longer need the Feature Branch as it's been deleted on the remote

git checkout main
## update the local copy of the main branch
git pull
# delete the local copy
git branch -D feature/TryingSomething

Managing changes and conflicts

Finding that someone else has modified the same file in a previous (or even concurrent) commit or in another branch that you're now merging your code with can be a truly terror-inducing prospect. I recently discovered how to use Visual Studio Code as the user interface for seeing what the conflict is and deciding whether to take their changes, keep my changes or take some combination of the two - all in the same code editor rather than learning lots of commands or jumping to another tool.

I highly recommend reading this post - How to use VS Code as your Git editor, difftool, and mergetool. I couldn't have explained it better myself!

Merge conflict

Going even faster with git town

Clearly this is a lot of commands to have to exectue each time you need to do some Feature work so there's a great tool that makes this much easier!

A quicker way to run through the steps starting from create a branch above is to use a tool called Git Town

# installs the tool
scoop install git-town

# makes a feature branch to work on and drops you into it!
git town hack feature/TrySomethingElse

Do some work...

Add-Content newfile.txt ''

Add and commit the changes:

git add .
git commit -m 'Your commit message'

This command then does all the hard work of getting your main up to date and merging your local branch and then pushing your work up to the remote (all in one line!)

git town sync

Create and merge a Pull Request as above

# cleans up and deletes redundant local branches
git town prune-branches
# get everything up to date
git town sync

Here's the whole process in action!:

Creating and completing Pull Requests in Azure Repos from command-line

If you're using Azure Repos (Azure DevOps) rather than GitHub then here's a neat way to create a Pull Request (using the Azure CLI DevOps extension) from the current feature branch without leaving the command prompt

Create a Pull request:

$prId=(az repos pr create --query 'pullRequestId' -o tsv)

Open in browser (NB: we can also use the --open flag with the az repos create command above):

az repos pr show --id $prId --open

Get details:

az repos pr show --id $prId --query '{Id:pullRequestId,Status:status,Title:title}' -o table

Set to Approved:

az repos pr set-vote --vote approve --id $prId

Complete the pull request:

az repos pr update --status completed --id $prId --squash true

Another way to clean up redundant local branches

I use this great tool from Maks Nemisj to remove local branches which are no longer present in my Git remote (usually because closing my Pull Request has also caused the remote branch to be deleted).

git removed-branches --prune --force

Some common questions

I hope to come back and answer these questions in due course:

Why are you making me type commands. Can't I just use the GUI?

What if I already made a Pull Request and want to make some more changes?

What about creating a new Repository from scratch?

What if I already have some files locally that I need to put into an existing Repository?

How does Git get my remote (i.e. GitHub / Azure DevOps) credentials?

Short answer - it gets it from Windows.

What if I'm behind a corporate proxy

What about deployment pipelines?

I'm hoping to write about those too in due course!

Last update: 2021-05-17