I have a local git repository that is configured to connect remotely over SSH on Gitlab (let's call it git@gitlab.com:myrepo/myproject.git
), after cloning repositories I like to keep only a specific folder of the project locally, I do it using the command:
git filter-branch --prune-empty --subdirectory-filter subdirectory HEAD~..
This command makes the local repository keeps track of the subdirectory
folder on the remote git project (and overlook all the files that are before this folder on my project). As long as I'm using it only for pulling it's fine... The problem is if I try to push changes to that remote branch, if I try I see the following error:
$ git push -u origin master
To git@gitlab.com:myrepo/myproject.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitlab.com:myrepo/myproject.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I haven't found anything to this specific case on git push --help
. Does anyone know if it's possible to push
on a remote folder when I only have a subfolder of the project on my local repository?