diff --git a/know-how/git-commands.md b/know-how/git-commands.md index 13080ef..c0c1132 100644 --- a/know-how/git-commands.md +++ b/know-how/git-commands.md @@ -91,20 +91,28 @@ Add executable flag on Windows: git update-index --chmod=+x git_mirror.sh ``` -Check the remote branch of a cloned repository and change it: +Backup a repository from a source with all branches and tags. ```bash +# fresh clone +git clone --mirror + +# existing local clone update +git fetch --all --tags --prune + +#Optional: zip it +tar czf repo-backup.git.tar.gz repo.git +``` + +Restore a repository to a new destination with all branches and tags. + +```bash +cd repo.git +git remote -v +git remote set-url origin git remote -v -git remote set-url origin xwr@vs-ssh.visualstudio.com:v3/xwr/jambor.pro/app-docker-compose - -git remote -v - -for branch in $(git branch -r | grep -v '\->'); do - git checkout ${branch#origin/} - git push -u origin HEAD - git push --tags origin -done +git push --mirror ``` Renaming branches: @@ -122,3 +130,5 @@ git branch -m main wikiMaster # Push git push origin HEAD ``` + +