Setting up git in Azure Cloud Shell

David Lee
3 min readDec 29, 2019

I am beginning to like the concept of using Azure Cloud Shell to help manage resources within my Azure Subscription(s). I find it useful to be able to execute scripts directly from within Cloud Shell because I love to automate common tasks such as managing Virtual Machines etc and this is an excellent platform to do just that. I do need those scripts local to my Azure Cloud Shell environment where I can easily manage and share those scripts using git with my peers.

Some pro tips: we can start an Azure Cloud Shell session directly from the Azure Portal, however, I prefer to directly use this shell.azure.com. If this is the first time you launch Azure Cloud Shell, you will need to create a storage account. I suggest for you to configure using the advance setting so you can control the storage account name, location etc. Another consideration is that you may decide to use an existing storage account with your peers where each person just needs their own file share.

After the Azure Cloud Shell session is launched, we can now see we are logged in to our subscription.

Doing a “dir” command would show our subscription information.

We can do a “cd $home” to navigate to our “home” directory. Because I like to keep my git repos organized into a folder called dev by convention, I would created a dev folder.

Next, I started creating a private git repository in my Azure DevOps instance and called it something meaningful, such as cloudshell. I am now ready to clone said repository into my dev folder. Before this, let’s fire off a few git commands to setup our git environment (globally).

git config --global user.name "first name last name"
git config --global user.email myemail@myemail.com

Next, we are ready to begin to do a git clone. If you are like me, using Azure DevOps, there’s a handy “Generate Git Credentials” that we can leverage to generate our git credentials which will provide us with the password. Store the password in the secure location because we wouldn’t be able to get it after the first time we view it.

We will be prompted for the password and git clone would be successful if we paste in the password.

The last step is to persist the password with the help of a credential helper.

git config credential.helper store

As we can see below, after running the credential helper command, we would be prompted for the password the first time when we do a git pull. The second time, we would not.

That’s it folks! Happy coding!

--

--

David Lee

Cloud Solution Architect/Software/DevOps Engineer