Backup to manage multiple git projects

Source: Internet
Author: User

When you have multiple git projects, how do you get these git projects to be backed up in a single folder?

One way to do this is to copy these Git projects to a folder each time with the CP command, so the problem is that the next backup is a hassle, either by deleting the old backup or renaming it.

Another good way to do this is to use git to manage these git projects. However, in a Git project, if you have a. git directory in a subfolder, Git automatically ignores it. Also, the backup should be a full backup. That is, the files in the. Gitignore of each Git project should also be backed up. The files are ignored when you use Git to manage them.

So, for the handling of these, I wrote a function script to handle, see below:

# Backup to manage multiple GIT projects function gitbackup () {[$# = 0] && new_cwd= '. ' | | new_cwd=$1 [!-D $new _cwd/.git] && echo "Not a git repository!" && return 1 suffix= ' LEP ' gitbackup= ". Gitbak. $suffix" old_cwd= ' pwd ' CD $n EW_CWD | | Return 1 for dir in ' ls ' do if [-D $dir/.git];  Then # Save the project's ignored files back up for F in ' Find $dir-name '. Gitignore "Do mv-f $f    $f. $suffix done rm-rf $dir/$gitbackup mv $dir/.git $dir/$gitbackup fi done git add-a git commit-m ' backup git project ' git config push.default current git push echo ' backup git proje    CT success! ' CD $old _CWD return 0}# restore backup of git project function Gitrestore () {[$# = 0] && new_cwd= '. ' | | new_cwd=$1 [!-D $n    Ew_cwd/.git] && echo "Not a git repository!" && return 1 suffix= ' LEP ' gitbackup= ". Gitbak. $suffix" Old_cwd= ' pwd ' cd $new _CWD | | Return 1 for dir in 'ls ' do if [-D $dir/$gitbackup]; Then MV $dir/$gitbackup $dir/.git fi # recover ignore file for f in ' Find $dir-name. Gitignore. $su    Ffix ' do mv-f $f ' dirname $f '/.gitignore-done echo ' Restore Git project success! ' CD $old _CWD return 0}# backup and restore function Gitbr () {gitbackup $ gitrestore "return 0;}

To use: Add these three functions to your. BASHRC or. ZSHRC, and then source it and let it take effect. Then run the following command under a directory:

Git init--bare git_pro_backupgit clone git_pro_backup git_procd git_progit clone your git project address git clone your other git project address ... gitbr or GITBR.


This way, your Git project is backed up, and the files that are ignored in your Git project are backed up.

When you're not careful about your git project that needs to be recovered, you can run the following command to recover: (assuming your git_pro_backup is in/tmp)

git clone/tmp/git_pro_backup git_procd git_progitrestore
This way, all your git projects revert back to the last time you ran GITBR or gitbackup.

Have any questions reply or q me: 281754179

Backup to manage multiple git projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.