Blog Post

Azure Platform Series: Push to GitHub repo with 2FA from a Mac using Personal Access Token

,

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

  1. Add the PAT into Keychain:
    Screen Shot 2020-06-07 at 17.25.40
  2. Create the Project Folder on the Mac:
    heymish$ mkdir devops-aks-middleware-api
  3. Initialise the local git repo
    heymish$ cd devops-aks-middleware-api
    heymish$ git init
  4. 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
  5. Create a local branch
    heymish$ git checkout -b master
  6. 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)"
  7. Now we want to add those files to be added to our initial commit:
    heymish$ git add .
    heymish$ git commit -m "initial code commit"
  8. 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"
  9. 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
  10. This will now ask me for credentials – which is the PAT I stored in the keychain before:
    Screen Shot 2020-06-07 at 17.19.36

    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.

  11. 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.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating