DevOps for the Terrified
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('https://get.scoop.sh') 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 ms-azure-devops.azure-pipelines code --install-extension ms-vscode.azure-account 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
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 user.name 'Your Name' git config --global user.email '[email protected]'
# details used for the current repository (i.e over-riding any global config) git config --local user.name 'Your Name' git config --local user.email '[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. Run git config --global user.email "[email protected]" git config --global user.name "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:
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 user.name 'Your Name' git config --local user.email '[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
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:
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).
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
Going even faster with
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!
# 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!:
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!