search

Home  >  Q&A  >  body text

git push branch pushes content under the selected folder

As shown below in a project

git add .
git commit -m "all"
git push 

The above will add everything to the master branch,

But I hope that all the files in the examples directory will be added to the gh-pages branch for easy demonstration

Do not want to create a git init

in the examples directory
git push origin gh-pages

will push all project files to gh-pages

And I only want the gh-pages branch to have all the files in the examples folder under the project, other files are not needed

Is there any other good way? Please give me some advice from the git master! !

What I want is to submit all the files of the project to the main branch, and all the files under the project folder example to be submitted to the branch of gh-pages

迷茫迷茫2811 days ago690

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-05-02 09:25:48

    Step 1

    Remove the dist directory from the project's .gitignore file (yeoman ignores the dist directory by default)

    Step 2

    Add dist directory to subtree:

    git add dist && git commit -m "Initial dist subtree commit"
    

    Step 3

    Use subtree to push the dist directory to the gh-pages branch:

    git subtree push --prefix dist origin gh-pages
    
    

    In this example, replace dist with example.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:25:48

    Use git push origin gh-pages
    origin is the name of your remote warehouse,
    gh-pages is the name of the branch you want to push

    reply
    0
  • 为情所困

    为情所困2017-05-02 09:25:48

    git checkout gh-pages
    git checkout master -- example
    git push origin gh-pages

    reply
    0
  • Cancelreply