Change default branch to "main" everywhere

commit 97a7c02e832dddab434431f5629e9450da685972 was my first attempt at
changing Jiri to stop uploading to the "master" branch by default. That
was insufficient because Jiri's logic that determines which branch to
push to falls back to the relevant project's `RemoteBranch` attribute,
which still defaulted to "master" (and wasn't overridden in any
manifests).

Changing the default `RemoteBranch` for projects is a much more invasive
change and it was difficult to determine exactly which "master"
references needed to be updated, so I went ahead and replaced all
"master" references in jiri's codebase with "main".

Aside from replacing "master" references with "main", the only code
change is in `project/project.go`, updating Jiri to change the default
`git push` target branch from "master" to "main" by overwriting
.git/config.

I confirmed locally that this fixes `jiri upload` for repos that don't
have a "main" branch, and that `jiri update` continues to work.

Bug: 327615030
Change-Id: I30f3e534b698aff4b98834781e87c29abbcd63fb
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/1038794
Reviewed-by: Danielle Kay <danikay@google.com>
Commit-Queue: Danielle Kay <danikay@google.com>
diff --git a/README.md b/README.md
index 0553f89..db8fe83 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,7 @@
 within the jiri root, and also includes other metadata, such as its remote url,
 the remote branch or revision it should track, and more.
 
-The `jiri update` command syncs the master branch of all local projects to the
+The `jiri update` command syncs the main branch of all local projects to the
 revision and remote branch specified in the manifest for each project. Jiri
 will create the project locally if it does not exist, and if run with the `-gc`
 flag, jiri will "garbage collect" any projects that are not listed in the
@@ -298,30 +298,30 @@
 represented by a single commit.  This constrains the way developers may use git
 to work on their changes.  In particular, they must use the --amend flag with
 all but the first git commit operation and they need to use git rebase to sync
-their pending code change with the remote master.  See Android's [repo command
+their pending code change with the remote.  See Android's [repo command
 reference][android repo] or Go's [contributing instructions][go contrib] for
 examples of how intricate the workflow for resolving conflicts between the
-pending code change and the remote master is.
+pending code change and the remote is.
 
 The rest of this section describes common development operations using `jiri
 upload`.
 
 ### Using feature branches
 
-All development should take place on a non-master "feature" branch.  Once the
-code is reviewed and approved, it is merged into the remote master via the
+All development should take place on a non-main "feature" branch.  Once the
+code is reviewed and approved, it is merged into the remote main branch via the
 Gerrit code review system.  The change can then be merged into the local
 branches with `jiri update -rebase-all`.
 
 ### Creating a new CL
 
-1. Sync the master branch with the remote.
+1. Sync the main branch with the remote.
   ```
   jiri update
   ```
 2. Create a new feature branch for the CL.
   ```
-  git checkout -b <branch-name> --track origin/master
+  git checkout -b <branch-name> --track origin/main
   ```
 3. Make modifications to the project source code.
 4. Stage any changed files for commit.
@@ -335,7 +335,7 @@
 
 ### Syncing a CL with the remote
 
-1. Sync the master branch with the remote.
+1. Sync the main branch with the remote.
   ```
   jiri update
   ```
@@ -343,11 +343,11 @@
   ```
   git checkout <branch-name>
   ```
-3. Sync the feature branch with the master branch.
+3. Sync the feature branch with the main branch.
   ```
-  git rebase origin/master
+  git rebase origin/main
   ```
-4. If there are no conflicts between the master and the feature branch, the CL
+4. If there are no conflicts between the main branch and the feature branch, the CL
    has been successfully synced with the remote.
 5. If there are conflicts:
   1. Manually [resolve the conflicts][github resolve conflict].
@@ -416,10 +416,10 @@
   jiri upload
   ```
 2. Once a CL meets the conditions for being submitted, it can be merged into
-   the remote master branch by clicking the "Submit" button on the Gerrit web
+   the remote main branch by clicking the "Submit" button on the Gerrit web
    UI.
 3. Delete the local feature branch after the CL has been submitted to Gerrit.
-  1. Sync the master branch to the laster version of the remote.
+  1. Sync the main branch to the laster version of the remote.
     ```
     jiri update
     ```
@@ -438,7 +438,7 @@
 
 Then, while still on the feature branch for A, create your feature branch for B.
 ```
-git checkout -b feature-B --track origin/master
+git checkout -b feature-B --track origin/main
 ```
 Then make your change and upload the CL for review according to the
 instructions above.
@@ -450,7 +450,7 @@
 ```
 jiri update # fetch update that includes feature A
 git checkout feature-B
-git rebase -i origin/master # if u see commit from A, delete it and then rebase
+git rebase -i origin/main # if u see commit from A, delete it and then rebase
 properly
 jiri upload # send new patch set for feature B
 ```
@@ -458,7 +458,7 @@
 
 This process can be extended for more than 2 CLs.  You must keep two things in mind:
 * always create the dependent feature branch from the parent feature branch, and
-* after a parent feature has been submitted, rebase feature-B onto origin/master
+* after a parent feature has been submitted, rebase feature-B onto origin/main
 
 ## FAQ
 
@@ -486,11 +486,11 @@
 [go contrib]: https://golang.org/doc/contribute.html#Code_review "Go Contribution Guidelines - Code Review"
 [jiri-wiki]: https://en.wikipedia.org/wiki/Ji%C5%99%C3%AD "Jiří"
 [manifests]: #manifests "manifests"
-[jiri manifest]: https://fuchsia.googlesource.com/jiri/+/refs/heads/master/manifest "jiri manifest"
+[jiri manifest]: https://fuchsia.googlesource.com/jiri/+/refs/heads/main/manifest "jiri manifest"
 [manifest doc]:/manifest.md "Jiri manifest"
 [filesystem doc]:/filesystem.md "Jiri filesystem"
 [hacking doc]:/HACKING.md "Jiri local updates"
 [behaviour]:/behaviour.md
 [how do i]:/howdoi.md
 [vanadium]: https://v.io/
-[cipd]: https://chromium.googlesource.com/infra/luci/luci-go/+/master/cipd/
+[cipd]: https://chromium.googlesource.com/infra/luci/luci-go/+/main/cipd/
diff --git a/behaviour.md b/behaviour.md
index e1d9740..0e6c9a3 100644
--- a/behaviour.md
+++ b/behaviour.md
@@ -45,7 +45,7 @@
 
 * Puts projects on `JIRI_HEAD`.
 * Removes un-tracked files.
-* if `-clean-all` flag is used, force deletes all the local branches, even **master**.
+* if `-clean-all` flag is used, force deletes all the local branches, even **main**.
 
 ### upload {#intended-project-upload}
 
diff --git a/cmd/jiri/branch.go b/cmd/jiri/branch.go
index 78dc065..6ae0532 100644
--- a/cmd/jiri/branch.go
+++ b/cmd/jiri/branch.go
@@ -52,7 +52,7 @@
 	Short:  "Show or delete branches",
 	Long: `
 Show all the projects having branch <branch> .If -d or -D is passed, <branch>
-is deleted. if <branch> is not passed, show all projects which have branches other than "master"`,
+is deleted. if <branch> is not passed, show all projects which have branches other than "main"`,
 	ArgsName: "<branch>",
 	ArgsLong: "<branch> is the name branch",
 }
@@ -63,7 +63,7 @@
 	flags.BoolVar(&branchFlags.forceDeleteFlag, "D", false, "Force delete branch from project. Similar to running 'git branch -D <branch-name>'")
 	flags.BoolVar(&branchFlags.listFlag, "list", false, "Show only projects with current branch <branch>")
 	flags.BoolVar(&branchFlags.overrideProjectConfigFlag, "override-pc", false, "Overrrides project config's ignore and noupdate flag and deletes the branch.")
-	flags.BoolVar(&branchFlags.deleteMergedFlag, "delete-merged", false, "Delete merged branches. Merged branches are the tracked branches merged with their tracking remote or un-tracked branches merged with the branch specified in manifest(default master). If <branch> is provided, it will only delete branch <branch> if merged.")
+	flags.BoolVar(&branchFlags.deleteMergedFlag, "delete-merged", false, "Delete merged branches. Merged branches are the tracked branches merged with their tracking remote or un-tracked branches merged with the branch specified in manifest(default main). If <branch> is provided, it will only delete branch <branch> if merged.")
 	flags.BoolVar(&branchFlags.deleteMergedClsFlag, "delete-merged-cl", false, "Implies -delete-merged. It also parses commit messages for ChangeID and checks with gerrit if those changes have been merged and deletes those branches. It will ignore a branch if it differs with remote by more than 10 commits.")
 }
 
@@ -96,21 +96,21 @@
 		}
 		if branch == "" {
 			var branches []string
-			master := ""
+			main := ""
 			for _, b := range state.Branches {
 				name := b.Name
 				if state.CurrentBranch.Name == b.Name {
 					name = "*" + jirix.Color.Green("%s", b.Name)
 				}
-				if b.Name != "master" {
+				if b.Name != "main" {
 					branches = append(branches, name)
 				} else {
-					master = name
+					main = name
 				}
 			}
 			if len(branches) != 0 {
-				if master != "" {
-					branches = append(branches, master)
+				if main != "" {
+					branches = append(branches, main)
 				}
 				fmt.Printf("%s: %s(%s)\n", jirix.Color.Yellow("Project"), state.Project.Name, relativePath)
 				fmt.Printf("%s: %s\n\n", jirix.Color.Yellow("Branch(es)"), strings.Join(branches, ", "))
@@ -305,7 +305,7 @@
 		if b.Tracking == nil {
 			rb := remote.RemoteBranch
 			if rb == "" {
-				rb = "master"
+				rb = "main"
 			}
 			trackingBranch = fmt.Sprintf("remotes/origin/%s", rb)
 		} else {
@@ -405,7 +405,7 @@
 				mergedBranches = make(map[string]bool)
 				rb := remote.RemoteBranch
 				if rb == "" {
-					rb = "master"
+					rb = "main"
 				}
 				if mbs, err := scm.MergedBranches("remotes/origin/" + rb); err != nil {
 					retErr = append(retErr, fmt.Errorf("Not able to get merged un-tracked branches: %s\n", err))
diff --git a/cmd/jiri/branch_test.go b/cmd/jiri/branch_test.go
index 44aa98e..2cca873 100644
--- a/cmd/jiri/branch_test.go
+++ b/cmd/jiri/branch_test.go
@@ -97,10 +97,10 @@
 	// current branch is not testBranch
 	i := 0
 	gitLocals[i].CreateBranch(testBranch)
-	gitLocals[i].CheckoutBranch("master", localProjects[i].GitSubmodules, false)
+	gitLocals[i].CheckoutBranch("main", localProjects[i].GitSubmodules, false)
 	branchWant = fmt.Sprintf("%s%s(%s)\n", branchWant, localProjects[i].Name, relativePath[i])
 	defaultWant = fmt.Sprintf("%sProject: %s(%s)\n", defaultWant, localProjects[i].Name, relativePath[i])
-	defaultWant = fmt.Sprintf("%sBranch(es): %s, *master\n\n", defaultWant, testBranch)
+	defaultWant = fmt.Sprintf("%sBranch(es): %s, *main\n\n", defaultWant, testBranch)
 
 	i = 2
 	gitLocals[i].CreateBranch(testBranch)
@@ -126,11 +126,11 @@
 
 	i = 6
 	gitLocals[i].CreateBranch(testBranch)
-	gitLocals[i].CreateBranch("master")
+	gitLocals[i].CreateBranch("main")
 	gitLocals[i].CheckoutBranch(testBranch, localProjects[i].GitSubmodules, false)
 	listWant = fmt.Sprintf("%s%s(%s)\n", listWant, localProjects[i].Name, relativePath[i])
 	defaultWant = fmt.Sprintf("%sProject: %s(%s)\n", defaultWant, localProjects[i].Name, relativePath[i])
-	defaultWant = fmt.Sprintf("%sBranch(es): *%s, master\n\n", defaultWant, testBranch)
+	defaultWant = fmt.Sprintf("%sBranch(es): *%s, main\n\n", defaultWant, testBranch)
 
 	i = 4
 	gitLocals[i].CreateBranch(testBranch)
@@ -193,7 +193,7 @@
 	gitLocals[i].CreateBranch(testBranch)
 	gitLocals[i].CheckoutBranch(testBranch, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile")
-	gitLocals[i].CheckoutBranch("master", localProjects[i].GitSubmodules, false)
+	gitLocals[i].CheckoutBranch("main", localProjects[i].GitSubmodules, false)
 
 	// Test when current branch is test branch
 	i = 2
@@ -270,7 +270,7 @@
 	gitLocals[i].CreateBranch(testBranch)
 	gitLocals[i].CheckoutBranch(testBranch, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile")
-	gitLocals[i].CheckoutBranch("master", localProjects[i].GitSubmodules, false)
+	gitLocals[i].CheckoutBranch("main", localProjects[i].GitSubmodules, false)
 
 	// Test when current branch is test branch
 	i = 2
@@ -468,14 +468,14 @@
 	for j := 0; j < 2; j++ {
 		writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+mergedIds[j])
 	}
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete2, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete2, "origin/main")
 	gitLocals[i].CheckoutBranch(branchToDelete2, localProjects[i].GitSubmodules, false)
 	for j := 0; j < 2; j++ {
 		writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+mergedIds[j])
 	}
 
 	i = 1
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].CheckoutBranch(branchToDelete1, localProjects[i].GitSubmodules, false)
 	for j := 0; j < 2; j++ {
 		writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+mergedIds[j])
@@ -484,8 +484,8 @@
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile"+changeIdPrefix+localIds[0])
 
 	i = 2
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+unmergedIds[0])
 
@@ -493,15 +493,15 @@
 
 	// Don't delete current branch with changes
 	i = 4
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+mergedIds[0])
 	newfile(t, localProjects[i].Path, "uncommitted.go")
 
 	// Don't delete branch when it has local commits
 	i = 5
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+localIds[0])
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile\n"+changeIdPrefix+mergedIds[0])
@@ -574,23 +574,23 @@
 
 	i := 0
 	gitLocals[i].CreateBranch(branchToDelete1)
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete2, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete2, "origin/main")
 
 	i = 1
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile")
 
 	i = 2
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile")
 
 	// project-3 has no branch
 
 	i = 4
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].CreateBranch(branchToDelete2)
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	writeFile(t, fake.X, localProjects[i].Path, "extrafile", "extrafile")
@@ -600,8 +600,8 @@
 
 	// Don't delete current branch with changes
 	i = 5
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 	gitLocals[i].CheckoutBranch(branchNotToDelete, localProjects[i].GitSubmodules, false)
 	newfile(t, localProjects[i].Path, "uncommitted.go")
 
@@ -655,15 +655,15 @@
 	i = 0
 	gitLocals[i].CreateBranch(branchToDelete1)
 	gitLocals[i].DeleteBranch(branchNotToDelete, gitutil.ForceOpt(true))
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 
 	i = 1
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].DeleteBranch(branchNotToDelete, gitutil.ForceOpt(true))
-	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchNotToDelete, "origin/main")
 
 	i = 2
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].DeleteBranch(branchNotToDelete, gitutil.ForceOpt(true))
 	gitLocals[i].CreateBranch(branchNotToDelete)
 
@@ -673,7 +673,7 @@
 	gitLocals[i].CreateBranch(branchNotToDelete)
 
 	i = 4
-	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/master")
+	gitLocals[i].CreateBranchWithUpstream(branchToDelete1, "origin/main")
 	gitLocals[i].DeleteBranch(branchNotToDelete, gitutil.ForceOpt(true))
 	gitLocals[i].CreateBranch(branchNotToDelete)
 	lc = project.LocalConfig{NoUpdate: true}
diff --git a/cmd/jiri/cmd.go b/cmd/jiri/cmd.go
index 547f625..ec5cd90 100644
--- a/cmd/jiri/cmd.go
+++ b/cmd/jiri/cmd.go
@@ -202,7 +202,7 @@
 Currently "git" is the default and only supported protocol.
 
 * remotebranch (optional) - The remote branch that the project will sync to.
-Defaults to "master".  The "remotebranch" attribute is ignored if "revision"
+Defaults to "main".  The "remotebranch" attribute is ignored if "revision"
 is specified.
 
 * revision (optional) - The specific revision (usually a git SHA) that the
diff --git a/cmd/jiri/doc.go b/cmd/jiri/doc.go
index 0479118..6147ede 100644
--- a/cmd/jiri/doc.go
+++ b/cmd/jiri/doc.go
@@ -71,7 +71,7 @@
 The jiri cl cleanup flags are:
  -f=false
    Ignore unmerged changes.
- -remote-branch=master
+ -remote-branch=main
    Name of the remote branch the CL pertains to, without the leading "origin/".
 
  -color=true
@@ -118,7 +118,7 @@
    The type of presubmit tests to run. Valid values: none,all.
  -r=
    Comma-seperated list of emails or LDAPs to request review.
- -remote-branch=master
+ -remote-branch=main
    Name of the remote branch the CL pertains to, without the leading "origin/".
  -set-topic=true
    Set Gerrit CL topic.
@@ -171,7 +171,7 @@
    jiri cl sync [flags]
 
 The jiri cl sync flags are:
- -remote-branch=master
+ -remote-branch=main
    Name of the remote branch the CL pertains to, without the leading "origin/".
 
  -color=true
@@ -213,7 +213,7 @@
    overwritten.
  -protocol=git
    The version control protocol used by the remote manifest project.
- -remote-branch=master
+ -remote-branch=main
    The branch of the remote manifest project to track, without the leading
    "origin/".
  -root=
@@ -278,7 +278,7 @@
 
 Jiri project clean - Restore jiri projects to their pristine state
 
-Restore jiri projects back to their master branches and get rid of all the local
+Restore jiri projects back to their main branches and get rid of all the local
 branches and changes.
 
 Usage:
@@ -288,7 +288,7 @@
 
 The jiri project clean flags are:
  -branches=false
-   Delete all non-master branches.
+   Delete all non-main branches.
 
  -color=true
    Use color to format output.
@@ -334,7 +334,7 @@
  -branches=false
    Show project branches.
  -nopristine=false
-   If true, omit pristine projects, i.e. projects with a clean master branch and
+   If true, omit pristine projects, i.e. projects with a clean main branch and
    no other branches.
 
  -color=true
@@ -355,7 +355,7 @@
 The jiri project shell-prompt flags are:
  -check-dirty=true
    If false, don't check for uncommitted changes or untracked files. Setting
-   this option to false is dangerous: dirty master branches will not appear in
+   this option to false is dangerous: dirty main branches will not appear in
    the output.
  -show-name=false
    Show the name of the current repo.
@@ -623,7 +623,7 @@
 Currently "git" is the default and only supported protocol.
 
 * remotebranch (optional) - The remote branch that the project will sync to.
-Defaults to "master".  The "remotebranch" attribute is ignored if "revision" is
+Defaults to "main".  The "remotebranch" attribute is ignored if "revision" is
 specified.
 
 * revision (optional) - The specific revision (usually a git SHA) that the
diff --git a/cmd/jiri/edit.go b/cmd/jiri/edit.go
index 3b87b5a..f4cadcc 100644
--- a/cmd/jiri/edit.go
+++ b/cmd/jiri/edit.go
@@ -145,12 +145,12 @@
 	}
 	for _, p := range editFlags.packages {
 		// The package name may contain "=" characters; so we split the string from the rightmost "=".
-		separatorPos := strings.LastIndex(p, "=");
-		if separatorPos == -1 || separatorPos == 0 || separatorPos == len(p) - 1 {
+		separatorPos := strings.LastIndex(p, "=")
+		if separatorPos == -1 || separatorPos == 0 || separatorPos == len(p)-1 {
 			return jirix.UsageErrorf("Please provide the -package flag in the form <package-name>=<version>")
 		} else {
 			packageName := p[:separatorPos]
-			version := p[separatorPos + 1:]
+			version := p[separatorPos+1:]
 			packages[packageName] = version
 		}
 	}
@@ -346,7 +346,7 @@
 			newRevision = rev
 		}
 		if newRevision == "" {
-			branch := "master"
+			branch := "main"
 			if p.RemoteBranch != "" {
 				branch = p.RemoteBranch
 			}
@@ -383,7 +383,7 @@
 			newRevision = rev
 		}
 		if newRevision == "" {
-			branch := "master"
+			branch := "main"
 			if i.RemoteBranch != "" {
 				branch = i.RemoteBranch
 			}
diff --git a/cmd/jiri/grep_test.go b/cmd/jiri/grep_test.go
index 8cc499f..da26075 100644
--- a/cmd/jiri/grep_test.go
+++ b/cmd/jiri/grep_test.go
@@ -42,7 +42,7 @@
 			Name:         projectPath,
 			Path:         filepath.Join(fake.X.Root, projectPath),
 			Remote:       fake.Projects[projectPath],
-			RemoteBranch: "master",
+			RemoteBranch: "main",
 		}
 		if err := fake.AddProject(p); err != nil {
 			t.Fatal(err)
diff --git a/cmd/jiri/import.go b/cmd/jiri/import.go
index f8cf90e..d25fdfb 100644
--- a/cmd/jiri/import.go
+++ b/cmd/jiri/import.go
@@ -29,7 +29,7 @@
 
 func init() {
 	cmdImport.Flags.StringVar(&flagImportName, "name", "manifest", `The name of the remote manifest project.`)
-	cmdImport.Flags.StringVar(&flagImportRemoteBranch, "remote-branch", "master", `The branch of the remote manifest project to track, without the leading "origin/".`)
+	cmdImport.Flags.StringVar(&flagImportRemoteBranch, "remote-branch", "main", `The branch of the remote manifest project to track, without the leading "origin/".`)
 	cmdImport.Flags.StringVar(&flagImportRevision, "revision", "", `Revision to check out for the remote.`)
 	cmdImport.Flags.StringVar(&flagImportRoot, "root", "", `Root to store the manifest project locally.`)
 
diff --git a/cmd/jiri/import_test.go b/cmd/jiri/import_test.go
index bb90d5f..e6b3579 100644
--- a/cmd/jiri/import_test.go
+++ b/cmd/jiri/import_test.go
@@ -26,7 +26,7 @@
 
 func setDefaultImportFlags() {
 	flagImportName = "manifest"
-	flagImportRemoteBranch = "master"
+	flagImportRemoteBranch = "main"
 	flagImportRevision = ""
 	flagImportRoot = ""
 	flagImportOverwrite = false
diff --git a/cmd/jiri/patch.go b/cmd/jiri/patch.go
index 22a9808..03f5588 100644
--- a/cmd/jiri/patch.go
+++ b/cmd/jiri/patch.go
@@ -356,7 +356,7 @@
 		} else if patchRebaseBranch != "" {
 			remoteBranch = patchRebaseBranch
 		} else {
-			remoteBranch = "master"
+			remoteBranch = "main"
 		}
 	} else if project, perr := currentProject(jirix); perr == nil {
 		p = &project
diff --git a/cmd/jiri/runp_test.go b/cmd/jiri/runp_test.go
index 2046f52..79da77d 100644
--- a/cmd/jiri/runp_test.go
+++ b/cmd/jiri/runp_test.go
@@ -50,7 +50,7 @@
 			Name:         projectPath,
 			Path:         filepath.Join(fake.X.Root, projectPath),
 			Remote:       fake.Projects[projectPath],
-			RemoteBranch: "master",
+			RemoteBranch: "main",
 		}
 		if err := fake.AddProject(p); err != nil {
 			t.Fatalf("%v", err)
diff --git a/cmd/jiri/source_manifest.go b/cmd/jiri/source_manifest.go
index ae0f49d..94a22ec 100644
--- a/cmd/jiri/source_manifest.go
+++ b/cmd/jiri/source_manifest.go
@@ -16,7 +16,7 @@
 	Short:  "Create a new source-manifest from current checkout",
 	Long: `
 This command captures the current project state in a source-manifest format.
-See https://github.com/luci/recipes-py/blob/master/recipe_engine/source_manifest.proto
+See https://github.com/luci/recipes-py/blob/main/recipe_engine/source_manifest.proto
 for its format.
 `,
 	ArgsName: "<source-manifest>",
diff --git a/cmd/jiri/source_manifest_test.go b/cmd/jiri/source_manifest_test.go
index e49213d..08b0118 100644
--- a/cmd/jiri/source_manifest_test.go
+++ b/cmd/jiri/source_manifest_test.go
@@ -96,11 +96,11 @@
 		GitCheckout: &project.SourceManifest_GitCheckout{
 			RepoUrl:  fake.Projects["manifest"],
 			Revision: revMap["manifest"],
-			FetchRef: "refs/heads/master",
+			FetchRef: "refs/heads/main",
 		},
 	}
 	for i := 0; i < numProjects; i++ {
-		ref := "refs/heads/master"
+		ref := "refs/heads/main"
 		if i == 2 {
 			ref = "refs/heads/test-branch"
 		} else if i == 3 {
diff --git a/cmd/jiri/status_test.go b/cmd/jiri/status_test.go
index 98b5ab3..78a2e47 100644
--- a/cmd/jiri/status_test.go
+++ b/cmd/jiri/status_test.go
@@ -41,11 +41,11 @@
 		gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProject.Name]))
 		writeFile(t, fake.X, fake.Projects[localProject.Name], "file1"+strconv.Itoa(i), "file1"+strconv.Itoa(i))
 		gitRemote.CreateAndCheckoutBranch("file-1")
-		gitRemote.CheckoutBranch("master", localProject.GitSubmodules, false)
+		gitRemote.CheckoutBranch("main", localProject.GitSubmodules, false)
 		file1CommitRev, _ := gitRemote.CurrentRevision()
 		file1CommitRevs = append(file1CommitRevs, file1CommitRev)
 		gitRemote.CreateAndCheckoutBranch("file-2")
-		gitRemote.CheckoutBranch("master", localProject.GitSubmodules, false)
+		gitRemote.CheckoutBranch("main", localProject.GitSubmodules, false)
 		writeFile(t, fake.X, fake.Projects[localProject.Name], "file2"+strconv.Itoa(i), "file2"+strconv.Itoa(i))
 		file2CommitRev, _ := gitRemote.CurrentRevision()
 		file2CommitRevs = append(file2CommitRevs, file2CommitRev)
@@ -270,8 +270,8 @@
 	gitLocals[0].CheckoutBranch("HEAD~1", localProjects[0].GitSubmodules, false)
 	gitLocals[1].CheckoutBranch("file-2", localProjects[1].GitSubmodules, false)
 	gitLocals[3].CheckoutBranch("HEAD~2", localProjects[3].GitSubmodules, false)
-	gitLocals[4].CheckoutBranch("master", localProjects[4].GitSubmodules, false)
-	gitLocals[5].CheckoutBranch("master", localProjects[5].GitSubmodules, false)
+	gitLocals[4].CheckoutBranch("main", localProjects[4].GitSubmodules, false)
+	gitLocals[5].CheckoutBranch("main", localProjects[5].GitSubmodules, false)
 
 	newfile(t, localProjects[0].Path, "untracked1")
 	newfile(t, localProjects[0].Path, "untracked2")
@@ -305,7 +305,7 @@
 	got := executeStatus(t, fake, "")
 	currentCommits := []string{file2CommitRevs[0], file1CommitRevs[1], latestCommitRevs[2], file1CommitRevs[3], latestCommitRevs[4], currentCommit5}
 	extraCommitLogs := [][]string{nil, nil, nil, nil, nil, extraCommits5}
-	currentBranch := []string{"", "file-2", "", "", "master", "master"}
+	currentBranch := []string{"", "file-2", "", "", "main", "main"}
 	changes := []string{"?? untracked1\n?? untracked2", "A  uncommitted.go", "A  uncommitted.go\n?? untracked1", "", "", ""}
 	want := expectedOutput(t, fake, localProjects, latestCommitRevs, currentCommits, changes, currentBranch, relativePaths, extraCommitLogs)
 	if !equal(got, want) {
@@ -338,18 +338,18 @@
 	setDefaultStatusFlags()
 	statusFlags.changes = false
 	statusFlags.checkHead = false
-	statusFlags.branch = "master"
+	statusFlags.branch = "main"
 	statusFlagsTest(t)
 
 	setDefaultStatusFlags()
 	statusFlags.checkHead = false
-	statusFlags.branch = "master"
+	statusFlags.branch = "main"
 	statusFlags.commits = false
 	statusFlagsTest(t)
 
 	setDefaultStatusFlags()
 	statusFlags.changes = false
-	statusFlags.branch = "master"
+	statusFlags.branch = "main"
 	statusFlagsTest(t)
 
 	setDefaultStatusFlags()
diff --git a/cmd/jiri/upload_test.go b/cmd/jiri/upload_test.go
index c730b6f..a9565ca 100644
--- a/cmd/jiri/upload_test.go
+++ b/cmd/jiri/upload_test.go
@@ -141,7 +141,7 @@
 	}
 	branch := "my-branch"
 	git := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"))
-	if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+	if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 		t.Fatal(err)
 	}
 	if err := git.CheckoutBranch(branch, localProjects[1].GitSubmodules, false); err != nil {
@@ -155,7 +155,7 @@
 		t.Fatal(err)
 	}
 
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, files)
 
 	uploadRemoteBranchFlag = "new-branch"
@@ -187,7 +187,7 @@
 	}
 	branch := "my-branch"
 	git := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"))
-	if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+	if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 		t.Fatal(err)
 	}
 	if err := git.CheckoutBranch(branch, localProjects[1].GitSubmodules, false); err != nil {
@@ -201,7 +201,7 @@
 		t.Fatal(err)
 	}
 
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, files[0:1])
 	assertUploadFilesNotPushedToRef(t, fake.X, gerritPath, expectedRef, files[1:])
 }
@@ -270,7 +270,7 @@
 			t.Fatal(err)
 		}
 		git := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"))
-		if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+		if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 			t.Fatal(err)
 		}
 		if err := git.CheckoutBranch(branch, localProjects[1].GitSubmodules, false); err != nil {
@@ -288,7 +288,7 @@
 		t.Fatal(err)
 	}
 
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, []string{"file-10", "file-20"})
 
@@ -323,7 +323,7 @@
 			t.Fatal(err)
 		}
 		git := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"))
-		if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+		if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 			t.Fatalf("%v", err)
 		}
 		if err := git.CheckoutBranch(branch, localProjects[i].GitSubmodules, false); err != nil {
@@ -344,7 +344,7 @@
 	if err := runUpload(fake.X, []string{}); err != nil {
 		t.Fatal(err)
 	}
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, []string{"file-10", "file-20"})
 
 	uploadSetTopicFlag = true
@@ -352,7 +352,7 @@
 		t.Fatal(err)
 	}
 	topic := fmt.Sprintf("%s-%s", os.Getenv("USER"), branch)
-	expectedRef = "refs/for/master%topic=" + topic
+	expectedRef = "refs/for/main%topic=" + topic
 
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, []string{"file-10", "file-20"})
 }
@@ -381,7 +381,7 @@
 	if err := git.Config("user.name", "John Doe"); err != nil {
 		t.Fatal(err)
 	}
-	if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+	if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 		t.Fatal(err)
 	}
 	if err := git.CheckoutBranch(branch, localProjects[1].GitSubmodules, false); err != nil {
@@ -406,7 +406,7 @@
 		t.Fatal(err)
 	}
 
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, localFiles)
 	assertUploadPushedFilesToRef(t, fake.X, localProjects[1].Path, branch, remoteFiles)
 }
@@ -429,7 +429,7 @@
 	}
 	branch := "my-branch"
 	git := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"))
-	if err := git.CreateBranchWithUpstream(branch, "origin/master"); err != nil {
+	if err := git.CreateBranchWithUpstream(branch, "origin/main"); err != nil {
 		t.Fatal(err)
 	}
 	if err := git.CheckoutBranch(branch, localProjects[1].GitSubmodules, false); err != nil {
@@ -445,7 +445,7 @@
 	if err := runUpload(fake.X, []string{}); err != nil {
 		t.Fatal(err)
 	}
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, append(files1, files2...))
 }
 
@@ -477,7 +477,7 @@
 	if err := runUpload(fake.X, []string{}); err != nil {
 		t.Fatal(err)
 	}
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 
 	assertUploadPushedFilesToRef(t, fake.X, gerritPath, expectedRef, files)
 
@@ -506,7 +506,7 @@
 	if err := os.Chdir(localProjects[1].Path); err != nil {
 		t.Errorf("failed to change current working directory due to error: %v", err)
 	}
-	// Create "refs/for/master" on remote
+	// Create "refs/for/main" on remote
 	files := []string{"file1"}
 	commitFiles(t, fake.X, files)
 	if err := runUpload(fake.X, []string{}); err != nil {
@@ -519,7 +519,7 @@
 	if err := runUpload(fake.X, []string{}); err != nil {
 		t.Errorf("upload failed due to error: %v", err)
 	}
-	expectedRef := "refs/for/master"
+	expectedRef := "refs/for/main"
 	gerritPath := fake.Projects[localProjects[1].Name]
 	assertUploadFilesNotPushedToRef(t, fake.X, gerritPath, expectedRef, files)
 }
diff --git a/gerrit/gerrit_test.go b/gerrit/gerrit_test.go
index dfebcf6..9a6ca83 100644
--- a/gerrit/gerrit_test.go
+++ b/gerrit/gerrit_test.go
@@ -368,11 +368,11 @@
 func TestReference(t *testing.T) {
 	t.Parallel()
 	testOpts := CLOpts{
-		RemoteBranch: "master",
+		RemoteBranch: "main",
 		Labels:       []string{"Commit-Queue+1"},
 		Reviewers:    []string{"a@example.com", "b@example.com"},
 	}
-	gold := "refs/for/master%l=Commit-Queue+1,r=a@example.com,r=b@example.com"
+	gold := "refs/for/main%l=Commit-Queue+1,r=a@example.com,r=b@example.com"
 	ref := Reference(testOpts)
 	if gold != ref {
 		t.Errorf("expecting %q, got %q", gold, ref)
diff --git a/gitutil/git.go b/gitutil/git.go
index 4b749df..d36ce1e 100644
--- a/gitutil/git.go
+++ b/gitutil/git.go
@@ -833,13 +833,13 @@
 }
 
 // DirExistsOnBranch returns true if a directory with the given name
-// exists on the branch.  If branch is empty it defaults to "master".
+// exists on the branch.  If branch is empty it defaults to "main".
 func (g *Git) DirExistsOnBranch(dir, branch string) bool {
 	if dir == "." {
 		dir = ""
 	}
 	if branch == "" {
-		branch = "master"
+		branch = "main"
 	}
 	args := []string{"ls-tree", "-d", branch + ":" + dir}
 	return g.run(args...) == nil
@@ -1056,7 +1056,7 @@
 		return err
 	}
 	if major >= 2 && minor >= 28 {
-		args = append(args, "--initial-branch=master")
+		args = append(args, "--initial-branch=main")
 	}
 	for _, opt := range opts {
 		switch typedOpt := opt.(type) {
diff --git a/howdoi.md b/howdoi.md
index 010329b..1739acf 100644
--- a/howdoi.md
+++ b/howdoi.md
@@ -62,7 +62,7 @@
 ### delete merged branches with different commits
 Run `jiri branch -delete-merged-cl`. This will check gerrit and delete all those branches whose commits have been submitted, by matching gerrit change list ID. **Use this with caution**.
 
-### get projects and branches other than master
+### get projects and branches other than main
 
 `jiri branch`
 
diff --git a/jiritest/fake.go b/jiritest/fake.go
index 4a1513f..8456c19 100644
--- a/jiritest/fake.go
+++ b/jiritest/fake.go
@@ -139,7 +139,7 @@
 // repository.
 func (fake FakeJiriRoot) DisableRemoteManifestPush() error {
 	dir := gitutil.RootDirOpt(filepath.Join(fake.remote, ManifestProjectPath))
-	if err := gitutil.New(fake.X, dir).CheckoutBranch("master", false, false); err != nil {
+	if err := gitutil.New(fake.X, dir).CheckoutBranch("main", false, false); err != nil {
 		return err
 	}
 	return nil
@@ -150,14 +150,14 @@
 func (fake FakeJiriRoot) EnableRemoteManifestPush() error {
 	dir := filepath.Join(fake.remote, ManifestProjectPath)
 	scm := gitutil.New(fake.X, gitutil.RootDirOpt(dir))
-	if ok, err := scm.BranchExists("non-master"); ok && err == nil {
-		if err := scm.CreateBranch("non-master"); err != nil {
+	if ok, err := scm.BranchExists("non-main"); ok && err == nil {
+		if err := scm.CreateBranch("non-main"); err != nil {
 			return err
 		}
 	} else if err != nil {
 		return err
 	}
-	if err := scm.CheckoutBranch("non-master", false, false); err != nil {
+	if err := scm.CheckoutBranch("non-main", false, false); err != nil {
 		return err
 	}
 	return nil
diff --git a/manifest.md b/manifest.md
index 7b96c1a..8b0b9e7 100644
--- a/manifest.md
+++ b/manifest.md
@@ -78,7 +78,7 @@
 
 * protocol (optional) - The protocol to use when cloning and syncing the repo. Currently "git" is the default and only supported protocol.
 
-* remotebranch (optional) - The remote branch that the project will sync to. Defaults to "master".  The "remotebranch" attribute is ignored if "revision" is specified.
+* remotebranch (optional) - The remote branch that the project will sync to. Defaults to "main".  The "remotebranch" attribute is ignored if "revision" is specified.
 
 * revision (optional) - The specific revision (usually a git SHA) that the project will sync to.  If "revision" is  specified then the "remotebranch" attribute is ignored.
 
diff --git a/project/manifest.go b/project/manifest.go
index df1d09a..afeeaea 100644
--- a/project/manifest.go
+++ b/project/manifest.go
@@ -265,7 +265,7 @@
 
 func (i *Import) fillDefaults() error {
 	if i.RemoteBranch == "" {
-		i.RemoteBranch = "master"
+		i.RemoteBranch = "main"
 	}
 	if i.Revision == "" {
 		i.Revision = "HEAD"
@@ -274,7 +274,7 @@
 }
 
 func (i *Import) RemoveDefaults() {
-	if i.RemoteBranch == "master" {
+	if i.RemoteBranch == "main" {
 		i.RemoteBranch = ""
 	}
 	if i.Revision == "HEAD" {
diff --git a/project/operations.go b/project/operations.go
index 4f37c92..ac3d7bc 100644
--- a/project/operations.go
+++ b/project/operations.go
@@ -108,7 +108,7 @@
 			}
 		}
 		// We must specify a refspec here in order for patch to be able to set
-		// upstream to 'origin/master'.
+		// upstream to 'origin/main'.
 		if err := scm.Config("remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"); err != nil {
 			return err
 		}
@@ -131,7 +131,7 @@
 			// we must invoke a dissociate manually. This involves running a
 			// repack, as well as removing the alternatives file. See the
 			// implementation of the dissociate flag in
-			// https://github.com/git/git/blob/master/builtin/clone.c#L1399 for
+			// https://github.com/git/git/blob/main/builtin/clone.c#L1399 for
 			// more details.
 			opts := []gitutil.RepackOpt{gitutil.RepackAllOpt(true), gitutil.RemoveRedundantOpt(true)}
 			if err := gitutil.New(jirix).Repack(opts...); err != nil {
@@ -270,8 +270,8 @@
 		jirix.Logger.Warningf("Project %s(%s) won't be deleted due to it's local-config\n\n", op.project.Name, op.source)
 		return nil
 	}
-	// Never delete projects with non-master branches, uncommitted
-	// work, or untracked content.
+	// Never delete projects with non-main branches, uncommitted work, or
+	// untracked content.
 	scm := gitutil.New(jirix, gitutil.RootDirOpt(op.project.Path))
 	branches, _, err := scm.GetBranches()
 	if err != nil {
diff --git a/project/project.go b/project/project.go
index bb09120..21d59d2 100644
--- a/project/project.go
+++ b/project/project.go
@@ -261,7 +261,7 @@
 
 func (p *Project) fillDefaults() error {
 	if p.RemoteBranch == "" {
-		p.RemoteBranch = "master"
+		p.RemoteBranch = "main"
 	}
 	if p.Revision == "" {
 		p.Revision = "HEAD"
@@ -270,7 +270,7 @@
 }
 
 func (p *Project) unfillDefaults() error {
-	if p.RemoteBranch == "master" {
+	if p.RemoteBranch == "main" {
 		p.RemoteBranch = ""
 	}
 	if p.Revision == "HEAD" {
@@ -649,7 +649,7 @@
 		return err
 	}
 	file := filepath.Join(gitDir, "JIRI_HEAD")
-	head := "refs/remotes/origin/master"
+	head := "refs/remotes/origin/main"
 	if p.Revision != "" && p.Revision != "HEAD" {
 		head = p.Revision
 	} else if p.RemoteBranch != "" {
@@ -676,9 +676,10 @@
 		return nil
 	}
 	scm := gitutil.New(jirix, gitutil.RootDirOpt(p.Path))
-	if err := scm.Config("--get", "remote.origin.push"); err != nil {
-		// remote.origin.push does not exist.
-		if err := scm.Config("remote.origin.push", "HEAD:refs/for/master"); err != nil {
+	defaultPushRefSpec := "HEAD:refs/for/main"
+	pushRefSpec, err := scm.ConfigGetKey("remote.origin.push")
+	if err != nil || pushRefSpec != defaultPushRefSpec {
+		if err := scm.Config("remote.origin.push", defaultPushRefSpec); err != nil {
 			return fmt.Errorf("not able to set remote.origin.push for project %s(%s) due to error: %v", p.Name, p.Path, err)
 		}
 	}
@@ -688,7 +689,7 @@
 			return fmt.Errorf("not able to set push.default for project %s(%s) due to error: %v", p.Name, p.Path, err)
 		}
 	}
-	jirix.Logger.Debugf("set remote.origin.push to \"HEAD:refs/for/master\" for project %s(%s)", p.Name, p.Path)
+	jirix.Logger.Debugf("set remote.origin.push to \"HEAD:refs/for/main\" for project %s(%s)", p.Name, p.Path)
 	return nil
 }
 
@@ -703,7 +704,7 @@
 
 func (p *Project) IsOnJiriHead(jirix *jiri.X) (bool, error) {
 	scm := gitutil.New(jirix, gitutil.RootDirOpt(p.Path))
-	jiriHead := "refs/remotes/origin/master"
+	jiriHead := "refs/remotes/origin/main"
 	var err error
 	if p.Revision != "" && p.Revision != "HEAD" {
 		jiriHead = p.Revision
@@ -1590,7 +1591,7 @@
 // CleanupProjects restores the given jiri projects back to their detached
 // heads, resets to the specified revision if there is one, and gets rid of
 // all the local changes. If "cleanupBranches" is true, it will also delete all
-// the non-master branches.
+// the non-main branches.
 func CleanupProjects(jirix *jiri.X, localProjects Projects, cleanupBranches bool) (e error) {
 	remoteProjects, _, _, err := LoadManifest(jirix)
 	if err != nil {
@@ -1655,7 +1656,7 @@
 }
 
 // resetLocalProject checks out the detached_head, cleans up untracked files
-// and uncommitted changes, and optionally deletes all the branches except master.
+// and uncommitted changes, and optionally deletes all the branches except main.
 func resetLocalProject(jirix *jiri.X, local, remote Project, cleanupBranches bool) error {
 	scm := gitutil.New(jirix, gitutil.RootDirOpt(local.Path))
 	headRev, err := GetHeadRevision(remote)
@@ -2243,7 +2244,7 @@
 				local := localProjects[key]
 				remote := remoteProjects[key]
 				scm := gitutil.New(jirix, gitutil.RootDirOpt(local.Path))
-				b := "master"
+				b := "main"
 				if remote.RemoteBranch != "" {
 					b = remote.RemoteBranch
 				}
diff --git a/project/project_test.go b/project/project_test.go
index 2adfc8a..9b807ba 100644
--- a/project/project_test.go
+++ b/project/project_test.go
@@ -85,7 +85,7 @@
 	projectRevision := p.Revision
 	if projectRevision == "" {
 		if p.RemoteBranch == "" {
-			projectRevision = "origin/master"
+			projectRevision = "origin/main"
 		} else {
 			projectRevision = "origin/" + p.RemoteBranch
 		}
@@ -207,7 +207,7 @@
 		}
 
 		// Initialize empty git repository.  The commit is necessary, otherwise
-		// "git rev-parse master" fails.
+		// "git rev-parse main" fails.
 		git := gitutil.New(jirix, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(path))
 		if err := git.Init(path); err != nil {
 			t.Fatal(err)
@@ -366,7 +366,7 @@
 	}
 
 	gitLocal := gitutil.New(fake.X, gitutil.RootDirOpt(localProjects[1].Path))
-	gitLocal.CreateBranchWithUpstream("A", "origin/master")
+	gitLocal.CreateBranchWithUpstream("A", "origin/main")
 	gitLocal.CreateBranch("B")
 	gitLocal.SetUpstream("B", "A")
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file1", "file1")
@@ -473,8 +473,8 @@
 		checkJiriRevFiles(t, fake.X, p)
 	}
 
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 
 	gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(localProjects[1].Remote))
 	remoteRev, err := gitRemote.CurrentRevision()
@@ -488,7 +488,7 @@
 		t.Fatal(err)
 	}
 
-	checkReadme(t, fake.X, localProjects[1], "master commit")
+	checkReadme(t, fake.X, localProjects[1], "main commit")
 	checkJiriRevFiles(t, fake.X, localProjects[1])
 
 	// Check that cache was updated
@@ -515,8 +515,8 @@
 
 	lc := project.LocalConfig{NoUpdate: true}
 	project.WriteLocalConfig(fake.X, localProjects[1], lc)
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 	gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
 	remoteRev, _ := gitRemote.CurrentRevision()
 	if err := fake.UpdateUniverse(false); err != nil {
@@ -845,8 +845,8 @@
 
 	lc := project.LocalConfig{Ignore: true}
 	project.WriteLocalConfig(fake.X, localProjects[1], lc)
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 	gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
 	remoteRev, _ := gitRemote.CurrentRevision()
 	if err := fake.UpdateUniverse(false); err != nil {
@@ -903,8 +903,8 @@
 
 	lc := project.LocalConfig{NoRebase: true}
 	project.WriteLocalConfig(fake.X, localProjects[1], lc)
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 	gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
 	remoteRev, _ := gitRemote.CurrentRevision()
 	if err := fake.UpdateUniverse(false); err != nil {
@@ -927,12 +927,12 @@
 		t.Fatal(err)
 	}
 	gitLocal := gitutil.New(fake.X, gitutil.RootDirOpt(localProjects[1].Path))
-	gitLocal.CheckoutBranch("master", localProjects[1].GitSubmodules, false)
+	gitLocal.CheckoutBranch("main", localProjects[1].GitSubmodules, false)
 
 	lc := project.LocalConfig{NoRebase: true}
 	project.WriteLocalConfig(fake.X, localProjects[1], lc)
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 	gitRemote := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
 	remoteRev, _ := gitRemote.CurrentRevision()
 	if err := fake.UpdateUniverse(false); err != nil {
@@ -942,7 +942,7 @@
 	localRev, _ := gitLocal.CurrentRevision()
 
 	if remoteRev == localRev {
-		t.Fatal("local branch master should not be updated")
+		t.Fatal("local branch main should not be updated")
 	}
 }
 
@@ -1183,7 +1183,7 @@
 
 // TestUpdateUniverseWithUncommitted checks that uncommitted files are not droped
 // by UpdateUniverse(). This ensures that the "git reset --hard" mechanism used
-// for pointing the master branch to a fixed revision does not lose work in
+// for pointing the main branch to a fixed revision does not lose work in
 // progress.
 func TestUpdateUniverseWithUncommitted(t *testing.T) {
 	localProjects, fake, cleanup := setupUniverse(t)
@@ -1428,9 +1428,9 @@
 	if testDirtyProjectDelete {
 		writeUncommitedFile(t, fake.X, localProjects[4].Path, "extra", "")
 	} else if testProjectWithBranch {
-		// Create and checkout master.
+		// Create and checkout main.
 		git := gitutil.New(fake.X, gitutil.RootDirOpt(localProjects[4].Path))
-		if err := git.CreateAndCheckoutBranch("master"); err != nil {
+		if err := git.CreateAndCheckoutBranch("main"); err != nil {
 			t.Fatal(err)
 		}
 	}
@@ -1552,7 +1552,7 @@
 }
 
 // TestUpdateUniverseRemoteBranch checks that UpdateUniverse can pull from a
-// non-master remote branch.
+// non-main remote branch.
 func TestUpdateUniverseRemoteBranch(t *testing.T) {
 	localProjects, fake, cleanup := setupUniverse(t)
 	defer cleanup()
@@ -1560,15 +1560,15 @@
 		t.Fatal(err)
 	}
 
-	// Commit to master branch of a project 1.
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	// Commit to main branch of a project 1.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 	// Create and checkout a new branch of project 1 and make a new commit.
 	git := gitutil.New(fake.X, gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
-	if err := git.CreateAndCheckoutBranch("non-master"); err != nil {
+	if err := git.CreateAndCheckoutBranch("non-main"); err != nil {
 		t.Fatal(err)
 	}
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-master commit")
-	// Point the manifest to the new non-master branch.
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-main commit")
+	// Point the manifest to the new non-main branch.
 	m, err := fake.ReadRemoteManifest()
 	if err != nil {
 		t.Fatal(err)
@@ -1576,7 +1576,7 @@
 	projects := []project.Project{}
 	for _, p := range m.Projects {
 		if p.Name == localProjects[1].Name {
-			p.RemoteBranch = "non-master"
+			p.RemoteBranch = "non-main"
 		}
 		projects = append(projects, p)
 	}
@@ -1584,11 +1584,11 @@
 	if err := fake.WriteRemoteManifest(m); err != nil {
 		t.Fatal(err)
 	}
-	// Check that UpdateUniverse pulls the commit from the non-master branch.
+	// Check that UpdateUniverse pulls the commit from the non-main branch.
 	if err := fake.UpdateUniverse(false); err != nil {
 		t.Fatal(err)
 	}
-	checkReadme(t, fake.X, localProjects[1], "non-master commit")
+	checkReadme(t, fake.X, localProjects[1], "non-main commit")
 }
 
 func TestUpdatedUniverseEnabledSubmodules(t *testing.T) {
@@ -1636,7 +1636,7 @@
 }
 
 // TestUpdateWhenRemoteChangesRebased checks that UpdateUniverse can pull from a
-// non-master remote branch if the local changes were rebased somewhere else(gerrit)
+// non-main remote branch if the local changes were rebased somewhere else(gerrit)
 // before being pushed to remote
 func TestUpdateWhenRemoteChangesRebased(t *testing.T) {
 	localProjects, fake, cleanup := setupUniverse(t)
@@ -1646,7 +1646,7 @@
 	}
 
 	gitRemote := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
-	if err := gitRemote.CreateAndCheckoutBranch("non-master"); err != nil {
+	if err := gitRemote.CreateAndCheckoutBranch("non-main"); err != nil {
 		t.Fatal(err)
 	}
 
@@ -1656,12 +1656,12 @@
 	}
 
 	// checkout branch in local repo
-	if err := gitLocal.CheckoutBranch("non-master", localProjects[1].GitSubmodules, false); err != nil {
+	if err := gitLocal.CheckoutBranch("non-main", localProjects[1].GitSubmodules, false); err != nil {
 		t.Fatal(err)
 	}
 
 	// Create commits in remote repo
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-master commit")
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-main commit")
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file1", "file1")
 	file1CommitRev, _ := gitRemote.CurrentRevision()
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file2", "file2")
@@ -1696,7 +1696,7 @@
 	}
 
 	gitRemote := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
-	if err := gitRemote.CreateAndCheckoutBranch("non-master"); err != nil {
+	if err := gitRemote.CreateAndCheckoutBranch("non-main"); err != nil {
 		t.Fatal(err)
 	}
 
@@ -1706,12 +1706,12 @@
 	}
 
 	// checkout branch in local repo
-	if err := gitLocal.CheckoutBranch("non-master", localProjects[1].GitSubmodules, false); err != nil {
+	if err := gitLocal.CheckoutBranch("non-main", localProjects[1].GitSubmodules, false); err != nil {
 		t.Fatal(err)
 	}
 
 	// Create commits in remote repo
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-master commit")
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-main commit")
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file1", "file1")
 	file1CommitRev, _ := gitRemote.CurrentRevision()
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file2", "file2")
@@ -1746,22 +1746,22 @@
 	}
 
 	gitRemote := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
-	if err := gitRemote.CreateAndCheckoutBranch("non-master"); err != nil {
+	if err := gitRemote.CreateAndCheckoutBranch("non-main"); err != nil {
 		t.Fatal(err)
 	}
 
 	// Create commits in remote repo
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-master commit")
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-main commit")
 	writeFile(t, fake.X, fake.Projects[localProjects[1].Name], "file1", "file1")
 	file1CommitRev, _ := gitRemote.CurrentRevision()
 	if err := gitRemote.CreateLightweightTag("testtag"); err != nil {
 		t.Fatalf("Creating tag: %s", err)
 
 	}
-	if err := gitRemote.CheckoutBranch("master", localProjects[1].GitSubmodules, false); err != nil {
+	if err := gitRemote.CheckoutBranch("main", localProjects[1].GitSubmodules, false); err != nil {
 		t.Fatal(err)
 	}
-	if err := gitRemote.DeleteBranch("non-master", gitutil.ForceOpt(true)); err != nil {
+	if err := gitRemote.DeleteBranch("non-main", gitutil.ForceOpt(true)); err != nil {
 		t.Fatal(err)
 	}
 
@@ -1832,7 +1832,7 @@
 
 		// Test case when local repo in on a branch
 		if i == 1 {
-			if err := gitLocal.CheckoutBranch("master", localProject.GitSubmodules, false); err != nil {
+			if err := gitLocal.CheckoutBranch("main", localProject.GitSubmodules, false); err != nil {
 				t.Fatal(err)
 			}
 		}
@@ -1895,26 +1895,26 @@
 	}
 
 	gitRemote := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(fake.Projects[localProjects[1].Name]))
-	if err := gitRemote.CreateAndCheckoutBranch("non-master"); err != nil {
+	if err := gitRemote.CreateAndCheckoutBranch("non-main"); err != nil {
 		t.Fatal(err)
 	}
 
-	// This will fetch non-master to local
+	// This will fetch non-main to local
 	if err := fake.UpdateUniverse(false); err != nil {
 		t.Fatal(err)
 	}
 
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-master commit")
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "non-main commit")
 
-	if err := gitRemote.CheckoutBranch("master", localProjects[1].GitSubmodules, false); err != nil {
+	if err := gitRemote.CheckoutBranch("main", localProjects[1].GitSubmodules, false); err != nil {
 		t.Fatal(err)
 	}
-	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "master commit")
+	writeReadme(t, fake.X, fake.Projects[localProjects[1].Name], "main commit")
 
 	gitLocal := gitutil.New(fake.X, gitutil.UserNameOpt("John Doe"), gitutil.UserEmailOpt("john.doe@example.com"), gitutil.RootDirOpt(localProjects[1].Path))
 
-	// This will create a local branch non-master
-	if err := gitLocal.CheckoutBranch("non-master", localProjects[1].GitSubmodules, false); err != nil {
+	// This will create a local branch non-main
+	if err := gitLocal.CheckoutBranch("non-main", localProjects[1].GitSubmodules, false); err != nil {
 		t.Fatal(err)
 	}
 
@@ -1946,8 +1946,8 @@
 	}
 
 	state := states[localProjects[1].Key()]
-	if shouldLocalBeOnABranch && state.CurrentBranch.Name != "non-master" {
-		t.Fatalf("local repo should be on branch(non-master) it is on %q", state.CurrentBranch.Name)
+	if shouldLocalBeOnABranch && state.CurrentBranch.Name != "non-main" {
+		t.Fatalf("local repo should be on branch(non-main) it is on %q", state.CurrentBranch.Name)
 	}
 
 	if rebaseAll {
@@ -2175,7 +2175,7 @@
 						Name:         "remoteimport1",
 						Remote:       "remote1",
 						Revision:     "HEAD",
-						RemoteBranch: "master",
+						RemoteBranch: "main",
 					},
 					{
 						Manifest:     "manifest2",
@@ -2200,7 +2200,7 @@
 						Name:          "project1",
 						Path:          "path1",
 						Remote:        "remote1",
-						RemoteBranch:  "master",
+						RemoteBranch:  "main",
 						Revision:      "HEAD",
 						GerritHost:    "https://test-review.googlesource.com",
 						GitHooks:      "path/to/githooks",
@@ -2273,7 +2273,7 @@
 				Name:         "project1",
 				Path:         filepath.Join(jirix.Root, "path1"),
 				Remote:       "remote1",
-				RemoteBranch: "master",
+				RemoteBranch: "main",
 				Revision:     "HEAD",
 			},
 			`<project name="project1" path="path1" remote="remote1"/>
diff --git a/project/source_manifest.go b/project/source_manifest.go
index 30c3884..014c60d 100644
--- a/project/source_manifest.go
+++ b/project/source_manifest.go
@@ -22,7 +22,7 @@
 	SourceManifestVersion = int32(0)
 )
 
-// This was created using proto file: https://github.com/luci/recipes-py/blob/master/recipe_engine/source_manifest.proto.
+// This was created using proto file: https://github.com/luci/recipes-py/blob/main/recipe_engine/source_manifest.proto.
 type SourceManifest_GitCheckout struct {
 	// The canonicalized URL of the original repo that is considered the “source
 	// of truth” for the source code. Ex.
@@ -45,14 +45,14 @@
 
 	// The ref that the task used to resolve/fetch the revision of the source
 	// (if any). Ex.
-	//   refs/heads/master
+	//   refs/heads/main
 	//   refs/changes/04/511804/4
 	//
 	// This should always be a ref on the hosted repo (not any local alias
 	// like 'refs/remotes/...').
 	//
 	// This should always be an absolute ref (i.e. starts with 'refs/'). An
-	// example of a non-absolute ref would be 'master'.
+	// example of a non-absolute ref would be 'main'.
 	FetchRef string `json:"fetch_ref,omitempty"`
 }
 
@@ -127,7 +127,7 @@
 			gc.Revision = rev
 		}
 		if proj.RemoteBranch == "" {
-			proj.RemoteBranch = "master"
+			proj.RemoteBranch = "main"
 		}
 		branchMap, err := scm.ListRemoteBranchesContainingRef(gc.Revision)
 		if err != nil {
diff --git a/update.go b/update.go
index 707262b..3198fb5 100644
--- a/update.go
+++ b/update.go
@@ -122,7 +122,7 @@
 	if u.Scheme != "http" && u.Scheme != "https" {
 		return "", fmt.Errorf("remote host scheme is not http(s): %s", repository)
 	}
-	u.Path = path.Join(u.Path, "+refs/heads/master")
+	u.Path = path.Join(u.Path, "+refs/heads/main")
 	q := u.Query()
 	q.Set("format", "json")
 	u.RawQuery = q.Encode()
@@ -155,7 +155,7 @@
 	if err := json.NewDecoder(r).Decode(&result); err != nil {
 		return "", err
 	}
-	if v, ok := result["refs/heads/master"]; ok {
+	if v, ok := result["refs/heads/main"]; ok {
 		return v.Value, nil
 	} else {
 		return "", fmt.Errorf("cannot find current commit")
diff --git a/update_test.go b/update_test.go
index 9233a9c..91a1567 100644
--- a/update_test.go
+++ b/update_test.go
@@ -19,7 +19,7 @@
 		w.Header().Set("Content-Type", "application/json")
 		io.WriteString(w, `)]}'
 {
-  "refs/heads/master": {
+  "refs/heads/main": {
     "value": "68661f351339107f397749c9689334fe9893bcea"
   }
 }`)