I've seen many variants of this question on SO but none of them had what I looking for. Say I have a repo ~/MyRepo/
:
$ ls -a ~/MyRepo
code.r junk.txt .git
In MyRepo
only the file code.r
is being tracked, and junk.txt
is not tracked.
And say I have a remote (e.g. on Dropbox) at ~/Dropbox/MyShare/
that a friend has access to (only for reading). The intent is for this remote to only contain my latest committed version of code.r
, and not contain junk.txt
. I'm trying to achieve the following: whenever I commit code.r
I want to be able to update (automatically if possible) the remote ~/Dropbox/MyShare/code.r
with the committed version of ~/MyRepo/code.r
.
I am aware of .gitignore
but not interested in that route because I have several untracked files that I want to ignore, and I only want to "push" the files I'm tracking to the remote.
I also tried the approach of doing a cloning
into ~/Dropbox/MyShare/
but cloning or pulling always seem to include tracked and untracked files, thus polluting my Remote.
My current solution is to have a post-commit hook under ~/MyRepo/.git/hooks/
that has explicit commands to individually copy all the "files I care about" to the remote. I don't like this solution because the "files I care about" can change, and I don't have to go and update the post-commit hook.
I am hoping there is a way to automatically make the last-committed versions available in ~/Dropbox/MyShare/
by some combination of git commands. I don't mind doing a single manual "push" command every time I commit in ~/MyRepo/
.
Here is what I tried based on one of the answers below, but I am still stumped.
# create my repo
mkdir foo
cd foo
git init
touch fileA fileB fileC
git add fileA
git commit -m 'new'
# now create remote
mkdir ../foo_remote
cd ../foo_remote
git init
cd ../foo
git remote add foo_remote ../foo_remote
bash-3.2$ git remote -v
foo_remote ../foo_remote (fetch)
foo_remote ../foo_remote (push)
Now when I try to push, I get this mean error message:
bash-3.2$ git push foo_remote master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ../foo_remote
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../foo_remote'
Any ideas where I'm going wrong?