Git: How to push a subdirectory to a separate branch of the same repository

The current project I am working on is limited to one git repository.
My current working directory looks something like this:

  *distribution files

  *src files

We have an Azure server set up to automatically deploy anything pushed to the ‘deploy’ branch of our repo. So the objective is to push src files to master and the content of the dist folder to the ‘deploy’ branch.

  • Git colors: How do I set colors for the upstream branch in “git branch -vv”?
  • Git case-sensitivity error — renaming and committing from Android Studio
  • Libgit2Sharp: get files in all commits between two tags
  • Git says I am ahead by 2 commits
  • How to get Vim Ctrl-P plugin to index files inside a git submodule
  • Should I check my TypeScript definition files for external libraries into git?
  • What I’ve been doing up until now is branching off master, deleting the src folder, and moving the contents of the dist folder to the root before pushing to deploy.

    I know ideally we would have separate repos, but that’s not an option currently. Is there an easier way to do this?

  • Git diff working incorrect - to many changes
  • MongoDB backup as text rather than binary for source control
  • On GitHub API - what is the best way to get the last commit message associated with each file?
  • Accidentally branched off of the wrong branch, and when I want to merge into the master I have to merge both branches
  • What does !*/ mean in .gitignore
  • How to require a fork with composer
  • One Solution collect form web for “Git: How to push a subdirectory to a separate branch of the same repository”

    The git-subtree command works great for this. From your master branch do:

    git subtree split --branch deploy --prefix dist/

    Just run that command every time you want to update the deploy branch. It will merge every commit in the dist subdir (of the current branch–presumably master) to the root of the deploy branch and maintain a full commit history. Note that only changes in the dist subdir will be merged. If a commit includes changes both to the dist subdir and other files in the repo, only the changes in the dist subdir get included.

    The tricky part is installation. As I understand it, the command is included with git 1.7.11 and higher. However, it’s in the “contrib” subtree, so it’s not installed by default. Search for “git-subtree” in your system’s package manager and install the package if it exists. If not, or if you are using an older version of git, the easiest way I’ve found is to install git-subtree from the author’s repo.

    git clone
    cd git-subtree/
    make install

    Once you get it installed, you can do various cool things with it as explained in the docs.

    Git Baby is a git and github fan, let's start git clone.