Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@nafeu nafeu commented Oct 7, 2017

Thank you good sir!

@shierro

This comment has been minimized.

Copy link

@shierro shierro commented Oct 8, 2017

Thanks mate! This was helpful :)

@thecjharries

This comment has been minimized.

Copy link

@thecjharries thecjharries commented Nov 24, 2017

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

This comment has been minimized.

Copy link

@codingedward codingedward commented Jun 3, 2018

Brilliant! Thanks.

@bdrazen

This comment has been minimized.

Copy link

@bdrazen bdrazen commented Jan 29, 2019

More concise approach:

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

@mhsalves

This comment has been minimized.

Copy link

@mhsalves mhsalves commented Oct 23, 2019

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

@ranolfi

This comment has been minimized.

Copy link

@ranolfi 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

This comment has been minimized.

Copy link

@thomasahle thomasahle commented May 17, 2020

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

@cavoirom

This comment has been minimized.

Copy link

@cavoirom cavoirom commented May 21, 2020

very nice, sir!

@joewoodhouse

This comment has been minimized.

Copy link

@joewoodhouse joewoodhouse commented Jul 23, 2020

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

This comment has been minimized.

Copy link

@juniovitorino juniovitorino commented Sep 28, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.