ServAce85
ServAce85

Reputation: 1622

Push files to remote git repository

I have a git repository set up on my laptop and I have created a clone on my thumb drive (to serve as a backup). I have set up the remote repo (the thumb drive) to ignore push errors. I am able to push the contents of the repository to the drive as desired (i.e. the git log shows the commits made on the laptop), but I would like to push the files themselves along with the repo changes. Does anyone know how to achieve this?

This is for use in Linux. If you need any additional information, just ask.

Upvotes: 1

Views: 2492

Answers (3)

crazyscot
crazyscot

Reputation: 11989

You seem to be saying that you want the files themselves to appear in the remote repo when you push to it? This isn't the usual use of git, but you can certainly do it; a number of people use it to have websites automatically deploy using git as a transport.

To achieve this, you need to set up a post-update hook in the destination repository (.git/hooks/post-update). Something like this ought to do the trick:

#!/bin/sh
git checkout -f

Remember to make sure it's executable.

Upvotes: 0

Kzqai
Kzqai

Reputation: 23062

git checkout master if you're not working with a bare repository.

Depending on your needs, a bare repository might not be what you want.

I'm going to assume that since creating a bare repository requires git clone somePath --bare you're probably working with a standard git repository without any of the files checked out.

Here are the use cases:

  • backup only: bare repository is probably better, because you will only have the space taken up by the repository, compressed, and not -also- the space from a working copy.

  • copy with full access to files, doesn't have to be up to date all the time: simple cloned repository, use git reset origin/master to wipe whatever is in the working copy in favor of the pushed changes.

  • copy with files is continually up to date: This is the trickiest case, because git doesn't update the working copy on push by default. Did a quick search, and one method mentioned is using a post-update hook: http://jennyandlih.com/pushing-remote-git-working-copy . Note that that probably isn't going to allow editing on that copy and replacement on push unless you delve into the stash-pop thing, which you can figure out on your own.

My recommendation, ( I do this all the time ), update the clone manually when you need to:

Create a simple clone (non-bare). Then git branch staging and git checkout staging. You now have a working copy, though you'll have to update it manually yourself by git rebase origin/master when you want to get changes. You can push changes from staging to master just fine. Just be aware that any "master" branch in that repository is probably going to be screwy with changes that get pushed to it, and effectively shouldn't be used or relied on.

Upvotes: 0

arie
arie

Reputation: 18972

but I would like to push the files themselves along with the repo changes

Not sure what you mean here.

Did you eventually create a bare repository on your thumb drive? If so, it's by design that there are no checked out files.

But you could use git archive to export your files or simply create a second, non-bare clone on your thumb drive.

And maybe check the docs concerning the working directory.

Upvotes: 2

Related Questions