Search code examples
python-3.xgitversion-controlbackuponedrive

Backup options for a project under version control with Git


I just arrived in a company which does not have access to GitHub or similar.

I was wondering about ways to backup my code using the private OneDrive which is given to each employee.

I just thought of moving my folder from the "document" directory to the "OneDrive" directory. But I was wondering whether changing the path will break my code.

Will it preserve the .git directory? Should I rerun git init (loosing the past history)?


Solution

  • You can move a Git repository from one path to another without affecting it. A Git repo is a self-contained entity (with the exception of global Git config) and the .git folder containing all Git files is just like any other folder (so it can be moved, deleted, etc.).

    If you want to use OneDrive as a backup, there are better options than simply copying your project over. Tools like restic or similar would allow you to keep your backup up to date in an efficient way.

    Note that you can also set OneDrive as a Git remote. Since it sounds like you are missing options such as GitHub or Bitbucket for your company, this is probably your best option.

    To add a remote called onedrive on OneDrive, you can run:

    git init --bare ~/OneDrive/<project>.git
    git remote add onedrive ~/OneDrive/<project>.git
    

    And then you can use onedrive as you would any other remote. For instance:

    git push --set-upstream onedrive master