<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-AU" xmlns:media="http://search.yahoo.com/mrss/">
  <id>https://david.gardiner.net.au/tags/Git.xml</id>
  <title type="html">David Gardiner - Git</title>
  <updated>2026-06-08T00:40:31.385Z</updated>
  <subtitle>Blog posts tagged with &apos;Git&apos; - A blog of software development, .NET and other interesting things</subtitle>
  <rights>Copyright 2026 David Gardiner</rights>
  <icon>https://www.gravatar.com/avatar/37edf2567185071646d62ba28b868fab?s=64</icon>
  <logo>https://www.gravatar.com/avatar/37edf2567185071646d62ba28b868fab?s=256</logo>
  <generator uri="https://github.com/flcdrg/astrojs-atom" version="3">astrojs-atom</generator>
  <author>
    <name>David Gardiner</name>
  </author>
  <link href="https://david.gardiner.net.au/tags/Git.xml" rel="self" type="application/atom+xml"/>
  <link href="https://david.gardiner.net.au/tags/Git" rel="alternate" type="text/html" hreflang="en-AU"/>
  <category term="Git"/>
  <category term="Software Development"/>
  <entry>
    <id>https://david.gardiner.net.au/2021/06/azure-devops-list-git-repositories</id>
    <updated>2021-06-09T12:30:00.000+09:30</updated>
    <title>Azure DevOps PowerShell Scripts - List all Git repositories</title>
    <link href="https://david.gardiner.net.au/2021/06/azure-devops-list-git-repositories" rel="alternate" type="text/html" title="Azure DevOps PowerShell Scripts - List all Git repositories"/>
    <category term="Azure DevOps"/>
    <category term="PowerShell"/>
    <category term="Git"/>
    <published>2021-06-09T12:30:00.000+09:30</published>
    <summary type="html">See Personal access tokens for instructions on how to create the personal access token.</summary>
    <content type="html">&lt;p&gt;&lt;img src=&quot;https://david.gardiner.net.au/_astro/devopsiconrepos96.B5OvG0Wx.svg&quot; alt=&quot;Azure Repos logo&quot; /&gt; If you want to list all the Git repositories for all projects in an Azure DevOps organisation, this script will return all the remote URLs.&lt;/p&gt;
&lt;p&gt;See &lt;a href=&quot;https://learn.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&amp;amp;WT.mc_id=DOP-MVP-5001655&quot;&gt;Personal access tokens&lt;/a&gt; for instructions on how to create the personal access token.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;param (
    [string] $organisation,
    [string] $personalAccessToken
)

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(&quot;:$($personalAccessToken)&quot;))
$headers = @{Authorization=(&quot;Basic {0}&quot; -f $base64AuthInfo)}

$result = Invoke-RestMethod -Uri &quot;https://dev.azure.com/$organisation/_apis/projects?api-version=6.0&quot; -Method Get -Headers $headers

$projectNames = $result.value.name

$projectNames | ForEach-Object {
    $project = $_

    $result = Invoke-RestMethod -Uri &quot;https://dev.azure.com/$organisation/$project/_apis/git/repositories?api-version=6.0&quot; -Method Get -Headers $headers

    $result.value.remoteUrl
} | Sort-Object
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It makes use of the &lt;a href=&quot;https://learn.microsoft.com/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-6.0&amp;amp;WT.mc_id=DOP-MVP-5001655&quot;&gt;Repositories - List&lt;/a&gt; REST API, so you could ask for any of the other properties instead of or in addition to &lt;code&gt;remoteUrl&lt;/code&gt; as well.&lt;/p&gt;
</content>
    <media:thumbnail url="https://david.gardiner.net.au/_astro/devopsiconrepos96.B5OvG0Wx.svg" width="96" height="96"/>
    <media:content medium="image" url="https://david.gardiner.net.au/_astro/devopsiconrepos96.B5OvG0Wx.svg" width="96" height="96"/>
  </entry>
  <entry>
    <id>https://david.gardiner.net.au/2020/05/wsl2-git-credentials</id>
    <updated>2020-05-21T10:12:00.000+09:30</updated>
    <title>Sharing Git credentials with WSL2</title>
    <link href="https://david.gardiner.net.au/2020/05/wsl2-git-credentials" rel="alternate" type="text/html" title="Sharing Git credentials with WSL2"/>
    <category term="Git"/>
    <category term="WSL2"/>
    <published>2020-05-21T10:12:00.000+09:30</published>
    <summary type="html">I&apos;m using WSL2 to manage my blog, but I noticed each time I went to run git push it was asking for my credentials again.</summary>
    <content type="html">&lt;p&gt;I&apos;m using WSL2 to manage my blog, but I noticed each time I went to run &lt;code&gt;git push&lt;/code&gt; it was asking for my credentials again. Why wasn&apos;t it remembering from last time? Turns out there&apos;s ways of storing git credentials, but even better, you can share the credentials you already have in Windows.&lt;/p&gt;
&lt;p&gt;As outlined in this Stack Overflow answer, assuming you have Git Credential Manager installed in Windows (and you probably do with a recent install of the Git command line tools), then run this in WSL2:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;git config --global credential.helper &quot;/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the extra escape to handle the space in &lt;code&gt;Program Files&lt;/code&gt;. With that set, &lt;code&gt;git push&lt;/code&gt; just worked.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Update 2022-07-08&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;See &lt;a href=&quot;https://docs.microsoft.com/windows/wsl/tutorials/wsl-git?WT.mc_id=DOP-MVP-5001655#git-credential-manager-setup&quot;&gt;Git Credential Manager setup&lt;/a&gt; for newer instructions on how to do this.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>https://david.gardiner.net.au/2019/07/azure-devops-force-push-default</id>
    <updated>2019-07-08T15:00:00.000+09:30</updated>
    <title>Azure DevOps - Default permissions for force push on a branch</title>
    <link href="https://david.gardiner.net.au/2019/07/azure-devops-force-push-default" rel="alternate" type="text/html" title="Azure DevOps - Default permissions for force push on a branch"/>
    <category term="Azure DevOps"/>
    <category term="Git"/>
    <category term="Azure DevOps"/>
    <published>2019-07-08T15:00:00.000+09:30</published>
    <summary type="html">How to resolve a permissions issue when trying to &apos;git push --force&apos; an Azure DevOps repository</summary>
    <content type="html">&lt;p&gt;This error caught me by surprise today:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C:\dev\git\project [feature ↓1 ↑2 +1 ~0 -0 !]&amp;gt; git push --force-with-lease
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (12/12), 1.61 KiB | 824.00 KiB/s, done.
Total 12 (delta 6), reused 8 (delta 4)
remote: Analyzing objects... (12/12) (8 ms)
remote: Storing packfile... done (115 ms)
remote: Storing index... done (81 ms)
To https://mytenancy.visualstudio.com/repo/_git/project
 ! [remote rejected]       feature -&amp;gt; feature (TF401027: You need the Git &apos;ForcePush&apos; permission to perform this action. Details: identity &apos;93086622-abb9-4886-b994-502e7f2afc21\me@mydomain.com&apos;, scope &apos;branch&apos;.)
error: failed to push some refs to &apos;https://mytenancy.visualstudio.com/repo/_git/project&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I was trying to push a change to a Git branch in Azure DevOps Repos. I&apos;d just done an interactive rebase to update history on the branch and was trying to force push my changes - something I&apos;ve done countless times before.&lt;/p&gt;
&lt;p&gt;Reviewing the permissions for this repository, the &lt;em&gt;Force push (rewrite history, delete branches and tags)&lt;/em&gt; permission was &lt;em&gt;Not Set&lt;/em&gt; (eg. neither explicitly allowed nor denied). Checking other projects and repositories, this was also the case, so what&apos;s different?&lt;/p&gt;
&lt;p&gt;Well one thing that&apos;s different is that I didn&apos;t create this branch - it was created by another developer. Force pushing to a shared branch is generally frowned upon (as if it isn&apos;t coordinated it can cause all kinds of problems), and so it seems DevOps helps guard against this problem by defaulting to granting the Force Push permission just to the branch creator (and also to users who are the Project administrator - as set in the Project details page of Project Settings).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://david.gardiner.net.au/_astro/force-push-permissions.KWJYLrYh_Z1Hkgzz.webp&quot; alt=&quot;Azure DevOps Branch user permissions&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Because I didn&apos;t create the original branch and I was not a project administrator in this particular project, no push for me!&lt;/p&gt;
&lt;p&gt;Check out the descriptions of the &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/devops/organizations/security/permissions?view=azure-devops#git-repository-object-level&quot;&gt;different permissions for Git repositories&lt;/a&gt; and the &lt;a href=&quot;https://learn.microsoft.com/azure/devops/organizations/security/default-git-permissions?view=azure-devops&quot;&gt;default Git repository and branch permissions&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
</feed>
