Skip to content

Instantly share code, notes, and snippets.

@tduarte
Last active April 17, 2026 03:58
Show Gist options
  • Select an option

  • Save tduarte/eac064b4778711b116bb827f8c9bef7b to your computer and use it in GitHub Desktop.

Select an option

Save tduarte/eac064b4778711b116bb827f8c9bef7b to your computer and use it in GitHub Desktop.
If you need to force push an subtree
git checkout master # you can avoid this line if you are in master...
git subtree split --prefix dist -b gh-pages # create a local gh-pages branch containing the splitted output folder
git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin
git branch -D gh-pages # delete the local gh-pages because you will need it: ref
@nafeu
Copy link
Copy Markdown

nafeu commented Oct 7, 2017

Thank you good sir!

@shierro
Copy link
Copy Markdown

shierro commented Oct 8, 2017

Thanks mate! This was helpful :)

@thecjharries
Copy link
Copy Markdown

Thanks! This was great.

For anyone else stumbling on this, here are some pertinent doc links. Chances are you've seen this stuff, but subtree was new to me.

@codingedward
Copy link
Copy Markdown

Brilliant! Thanks.

@bdrazen
Copy link
Copy Markdown

bdrazen commented Jan 29, 2019

More concise approach:

git push origin `git subtree split --prefix dist master`:gh-pages --force

@mhsalves
Copy link
Copy Markdown

OMG ! You saved my life ! I had tried for a long time ! Tks

@ranolfi
Copy link
Copy Markdown

ranolfi commented Dec 15, 2019

More concise approach:

git push origin `git subtree split --prefix dist master`:gh-pages --force

This is perfect. Thanks.

@thomasahle
Copy link
Copy Markdown

This all requires that dist is already committed to master. Is it possible to just push something not committed?

@cavoirom
Copy link
Copy Markdown

very nice, sir!

@joewoodhouse
Copy link
Copy Markdown

I love this, but it would be nice if the local and remote branches weren't named the same in your example - I can never remember what order gh-pages:gh-pages is :)

@juniovitorino
Copy link
Copy Markdown

More concise approach:

git push origin `git subtree split --prefix dist master`:gh-pages --force

For those using fish shell:

git push origin (git subtree split --prefix dist master):gh-pages --force

@Vandivier
Copy link
Copy Markdown

much amz very

@tim-minshall
Copy link
Copy Markdown

This is amazing thank you!!!

@sampolahtinen
Copy link
Copy Markdown

brilliant thanks! :)

@dwgrossberg
Copy link
Copy Markdown

still here, thank you again

@PancakePhilarmonych
Copy link
Copy Markdown

git push origin git subtree split --prefix dist master:gh-pages --force

Thank you so much! 🫶🏻

@ryanwild
Copy link
Copy Markdown

Thanks, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment