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.

  • Excluding files from Getting rebased
  • git remote branch deleted but still appears in 'branch -a'
  • Check history of the git pulls made on a local repository from a remote branch
  • Revert merge Git-Flow
  • Create public fork of private code, with private pushing changes to the public
  • Git or Subversion for binary files
  • 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?

  • Whitelisting and subdirectories in Git
  • How do I use a post-receive hook to conditionally run commands depending on the branch updated?
  • Git - Remove All of a Certain Type of File from the Index
  • Git: how to push submodule to a remote repository?
  • How to ask git if the repository is in a conflict stage?
  • Git command to add, commit, and push to the correct branch
  • 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.