2

I am starting to use git. I will be the only one using the repo. For backup purposes I want to regularly push my repo to a remote Server.

Using git push gives me the

git push error 'remote rejected] master -> master (branch is currently checked out)'.

To cope with this, I created a dummy branch on the remote location and checkout this branch.

Pushing into master now works fine.

I am a little worried since I can't see the actual files in my remote location. Will this work as a backup system? When I switch to the master branch in my remote location all files are present. Will the backup files be generated while pushing into a none active branch or will they be generated once the branch becomes active?

Hope you can help to clear things up.

Regards.

SirBlack
  • 29
  • 2

3 Answers3

3

I would rather push to a bare repo (so, with no branch checked out), or even better (from a backup perspective), to a bundle:
See "Backup a Local Git Repository".

That way, you only need to create locally one file, that you can easily backup elsewhere.
(if you don't need the history, git archive works too)

But if you have already a server for git repos, you need to reference on it a bare repo in order to avoid any push error message.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note, to push to a bare repo: http://stackoverflow.com/questions/3382679/git-how-do-i-update-my-bare-repo – VonC Aug 11 '11 at 12:27
  • Thanks for the answer. Pushing to a bare repo will copy the refs from the .git-Folder for all branches? If I keep on doing it the way it is setup right now, I will only push the refs of the master-branch right? – SirBlack Aug 11 '11 at 12:40
  • @SirBlack: you can push only the current branch or all branches (and tags) at the same time. Basically, this is the same push than a non-bare repo. – VonC Aug 11 '11 at 12:49
  • So backing up the refs will save all the information to regenerate the files and the file structure? – SirBlack Aug 11 '11 at 13:03
  • @SirBlack: backing up the ref from the `.git`? No need: you just create a bare repo on the server, and push everything from your local repo to that bare repo. No need to select sub-directories within a `.git`. – VonC Aug 11 '11 at 14:46
1

If your backup location has branch backup checked out, and you push to branch master, then when you come to backup files at your backup location (even if you were to do a git pull on your backup location) it would only backup the files that are in the currently checked out branch.

It will however, backup your .git folder which contains the refs to your other branches. So in theory, you are backing up the whole repo

JamesHalsall
  • 13,224
  • 4
  • 41
  • 66
  • 1
    More than just "in theory." If you back up your .git folder, you _are_ backing up the entire repo. – Karl Bielefeldt Aug 11 '11 at 14:26
  • @Karl, yeah... my poor choice of words. What I meant was it wouldn't backup those exact files but you would definitely be able to retrieve them from the refs – JamesHalsall Aug 11 '11 at 14:29
-1

Update (git pull) your remote branch, and you will see your changes.

TiansHUo
  • 8,509
  • 7
  • 45
  • 57