This is another blog post in the series of how to #MakeStuffGo in Azure.
Background:
I have some code on my Mac. I need to put it into an empty GitHub repo for later deployment in Azure and I have to use a Personal Access Token (PAT). I was provided the URL of the repo and given the PAT so stored that in the keychain on my Mac.
#MakeStuffGo with PAT, GitHub and a Mac
- Add the PAT into Keychain:
- Create the Project Folder on the Mac:
heymish$ mkdir devops-aks-middleware-api
- Initialise the local git repo
heymish$ cd devops-aks-middleware-api heymish$ git init
- Add the remote git repository – I have called mine origin – it could be anything
heymish$ git remote add origin https://github.com/<clientrepo>/devops-aks-middleware-api.git
- Create a local branch
heymish$ git checkout -b master
- Do some stuff
For me I was just copying in code that we had worked on so far – so copied that into the directory and did:
git status <list of files that I've added> "nothing added to commit but untracked files present (use "git add" to track)"
- Now we want to add those files to be added to our initial commit:
heymish$ git add . heymish$ git commit -m "initial code commit"
- Now comes the hard part – getting the 2FA stuff going with GitHub.
a) we need to setup the GitHub email address we’ll use
b) we need to setup the GitHub username we’ll use
heymish$ git config --global user.email "hamishwatson59@clientx.com" heymish$ git config --global user.name "TheHamishWatson"
- Now we will push our local changes to the remote branch.
The -u flag indicates that we are pushing local changes upstream to origin
git push -u origin master
- This will now ask me for credentials – which is the PAT I stored in the keychain before:
I type in the password for my keychain and I only click Allow – I’m ok to type in the password every time I need to auth to GitHub – I could click Always Allow – it’s just a personal thing.
- Git will now push my local changes up to the repository and I can now start to edit code and collaborate with my clients developers.
So there you go – not too hard and things are nice and secure. There are other ways to use GitHub – ssh vs https which I’ve done here. But for https the above method using a Personal Access Token is pretty straightforward.
Yip.