regattanetwork's avatar

Change a github branch for a site already setup with Forge

The only way I've been able to change the branch used for deployment in Forge is to remove the repository and add it again. Would be helpful if there was an easier way to do it.

1 like
14 replies
bashy's avatar

What do you mean by change a Github branch? Switch to a new/different branch and pull that?

bashy's avatar

Not sure if it uses current branch via the directory but, SSH in and switch branch then update?

djave_co's avatar

You can do this now, in the site settings just scroll down a bit:

Imgur

Hope this helps someone!

2 likes
adampatterson's avatar

@djave_co That caught me, it doesn't actually do anything. Unless this feature is newer than my sites.

Forge provisions the sites using a single branch shallow commit

git clone --depth 50 --single-branch -b staging [email protected]:adampatterson/repo repo

sheriffderek's avatar

@djave_co Anyone else landing here, as of 2025 - it's there. Midway down the Deployments page.

2 likes
adampatterson's avatar

If you need to change branches on a staging or test server you'll need to adjust the .git/config file.

When Forge provisions a site it's cloned by using a single branch shallow clone using --single-branch which will prevent you from checking out another branch.

git clone --depth 50 --single-branch -b staging [email protected]:adampatterson/repo repo

git branch -r
  origin/staging

This locks the repo to the staging branch.

[remote "origin"]
    url = [email protected]:adampatterson/repo
    fetch = +refs/heads/staging:refs/remotes/origin/staging

Run git config remote.origin.fetch refs/heads/*:refs/remotes/origin/* to allow multiple branches.

Then run git fetch to update the local branches.

[remote "origin"]
    url = [email protected]:adampatterson/maker
    fetch = refs/heads/*:refs/remotes/origin/*
git branch -r
  origin/dev
  origin/main
  origin/staging

git fetch origin then git switch main

Locking the repo git config remote.origin.fetch refs/heads/main:refs/remotes/origin/main

10 likes
adampatterson's avatar

@cosminbosutar Awesome!

I was getting really frustrated when I'd change the branch in Forge and then it was stuck. It was only when I looked at the provision script did I notice how it was checked out.

1 like
AlCo2's avatar

that' exactly the solution I needed, thanks.

tylerwiegand's avatar

i wish the branch selector in the interface would do something like this...

git config --add remote.origin.fetch +refs/heads/BRANCH_NAME:refs/remotes/origin/BRANCH_NAME
git fetch origin BRANCH_NAME
git checkout -b BRANCH_NAME origin/BRANCH_NAME

^ that seems to work though, if anyone is interested

3 likes

Please or to participate in this conversation.