2

I have a git repository created by using git clone www.someserver.com/mygitrepo. I want to maintain an offline backup of this repository entire source code and history, would it be sufficient to call git pull and git fetch in the repository every once in a while? As far as I found git pull should update the current local branch from the remote one, and git fetch should update all the local branches from their respective remote branches. But does git fetch also downloads branches added after the initial git clone call? Is it OK to assume I have a full up-to-date backup by using this method? Is it enough to just call get fetch? What is the best way to achieve a full backup?

EDIT:

Just to clarify, I'm less interested in getting all the branches specifically, I'm more interested in maintaining a full copy of the repository including tags and such for the event that the server will be unavailable.

UnTraDe
  • 3,359
  • 10
  • 29
  • 57
  • Possible duplicate of [How to fetch all git branches](http://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches) – A.L Feb 27 '16 at 19:06
  • Did you find a solution in the possible duplicate question? – A.L Feb 27 '16 at 20:48
  • @A.L Is the answer there also cover tags? And is it safe to use that method to maintain a full offline backup with the entire history and source code? I didn't really understood if that's the case from the answer there, I need to be sure that this is the way to maintain complete offline backups of a git repository. – UnTraDe Feb 28 '16 at 06:13

1 Answers1

1

no it will not automatically fetch all branches. But you can use:

for remote in `git branch -r`; do git branch --track $remote; done
git fetch --all
git pull --all

source: How to fetch all git branches

but if you use it as a back-up you can have problems with history changes on the server. (like the commits that have been changed will also be change on the backkup, you can set it to not do that, but then it just stops backing up from the moment you change a old commit)

Community
  • 1
  • 1
Sam
  • 58
  • 5