How you can work with Git

An example

We've just started and are about to code some terraform modules. We've created the local folder c:/Terraform/subscriptions/dev/rg-dev/ and in that folder we have three files,, och We open up git-bash navigate to the folder.:
$ cd c:/Terraform/subscriptions/dev/rg-dev

WE initiate Git in the folder:
$ git init
Initialized empty Git repository in c:/Terraform/subscriptions/dev/rg-dev/.git/

We add all changed files to Git index:
$ git add .

…and then we make our first commit.:
$ git commit -m "Started development"

We create tf file and add some code in that file. Then we add it and commit it.
$ git add
$ git commit -m "Created"

We modify our and When we're satisfied we check status.
$ git status
On branch master
Changes not staged for commit:

We can see here that we have two modified files which is not yet added. We add the files and do another commit:
$ git add .
$ git commit -m "Created variables and edited"

Now the first version of our code is done and we want to send it ot to our remote repository at Azure DevOps Repos. Now we add the remote:
$ git remote add origin

and push our files to the remote repository:
$ git push origin master

We think of a new function we like to add. We're not sure our idea will work so we create a branch of our repository to test that it works.
$ git branch testing-new-function

We now have two branches of our repo. We can change to our new branch using:
$ git checkout testing-new-function

We code some new functionality. When we've tested it and we're happy that it works as expected, so we decide we want this in our in our dev code. We make a pull request in Azure DevOps so the code can be checked and approved by other members of the team. It gets the "thumbs up" so we merge it with our master branch:
$ git checkout master
$ git merge testing-new-function -m "New functionality"

We remove the testing branch we no longer need.
$ git branch -d testing-new-function

Finally, we push everything to our remote repository:
$ git push origin master

Joakim Nordin

Joakim Nordin