A simple bash script for backing up local repositories to bitbucket private.
The script runs over a directory and checks if each subfolder is a git repo. If it is; it will stash any local changes then pull ALL remote branches down locally. It then creates a new private bitbucket repository for each local one. Then it as a new remote called bitbucket
to each project. Finally it pushes all branches and tags to new repository on bitbucket.
- Git clone the repo to somewhere sensible
- Create a hidden
.r2b-credentials.sh
file in the$HOME
dir of the user.
touch $HOME/.r2b-credentials.sh
- Add the following to
.r2b-credentials.sh
replacing<YOUR_USER>
,<YOUR_PASSWORD>
and<YOUR_TEAM>
to your BitBucket account credentials and Team name. Use the.r2b-credentials.example.sh
as an example
export BITBUCKET_TEAM='<YOUR_TEAM>'
export BITBUCKET_USER='<YOUR_USER>'
export BITBUCKET_PASSWORD='<YOUR_PASSWORD>'
- Symlink the full path to the scripts location to your bin directory so you can run the script from any dir.
sudo ln -s /full/path/to/repo-to-bitbucket/repo-to-bitbucket.sh /usr/local/bin/repo-to-bitbucket
- Navigate to a folder containing a collection of other git repository and run the script using
repo-to-bitbucket
. For example file structure below shows a folder calledmy-git-projects
which contains a bunch of other repositories. To back those up, run the script frommy-git-projects
.
.
+-- my-git-projects
| +-- some-cool-app
| +-- .git
| +-- other-fun-app
| +-- .git
| +-- also-fun-app
| +-- .git