Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a git ignored folder to a subtree branch?

Tags:

git

github

I have a yeoman angular app and by default the dist folder came ignored. So when I try this: git subtree push --prefix dist origin gh-pages it fails because it is ignored. I don't want to push the dist folder to the master branch, I only want to push it to the gh-pages branch.

How can I achieve this?

like image 373
brielov Avatar asked Oct 06 '14 20:10

brielov


People also ask

How do you push to a subtree?

subtree : push: allow specifying a local rev other than HEAD ' git push '(man) lets you specify a mapping between a local thing and a remot ref. So smash those together, and have git subtree push let you specify which local thing to run split on and push the result of that split to the remote ref.

Does gitignore work in subdirectories?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

How to git ignore specific files?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

What is a subtree Git?

git subtree lets you nest one repository inside another as a sub-directory. It is one of several ways Git projects can manage project dependencies. Why you may want to consider git subtree. Management of a simple workflow is easy.


1 Answers

I ended up writing a script for this. It creates a temporary commit with an updated .gitignore file with lines containing gh-pages removed.

After pushing the commit is discarded. The if statement is there so you don't accidentally lose work.

STATUS="$(git status)"

if [[ $STATUS == *"nothing to commit, working tree clean"* ]]
then
    sed -i "" '/gh-pages/d' ./.gitignore
    git add .
    git commit -m "Edit .gitignore to publish"
    git push origin `git subtree split --prefix gh-pages master`:gh-pages --force
    git reset HEAD~
    git checkout .gitignore
else
    echo "Need clean working directory to publish"
fi

Note that before v2.9.1, the status was nothing to commit, working directory clean

like image 129
Matt Zeunert Avatar answered Oct 16 '22 16:10

Matt Zeunert