Git Clone Repo Preserving History
reference
https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository
Repository Origin account: jalbertomr
https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository
Repository Origin account: jalbertomr
https://github.com/jalbertomr/project-reactor-essentials-test
New Destiny Repository (To be reated in another account) account: cuentafulana
create new Repository: cuentafulana/clonedRepoTest
1.- Create New Repository on the account where the Repository will be cloned
2.- Invite te original account to be a collaborator sending an invitation
3.- The Account of the Source Repository accepts the invitation in order to to push on the empty cloned repository
Now the source account can do push to the cloned Repository of the other account.
4.- Mirroring the repository, open git bash.
5.- Create a bare clone of the repository
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ git clone --bare https://github.com/jalbertomr/project-reactor-essentials-test
Cloning into bare repository 'project-reactor-essentials-test.git'...
remote: Enumerating objects: 603, done.
remote: Counting objects: 100% (603/603), done.
remote: Compressing objects: 100% (118/118), done.
remote: Total 603 (delta 149), reused 598 (delta 144), pack-reused 0
Receiving objects: 100% (603/603), 128.95 KiB | 1.08 MiB/s, done.
Resolving deltas: 100% (149/149), done.
6.- Mirror push to the new repository
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ ls
project-reactor-essentials-test.git/
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ cd project-reactor-essentials-test.git
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/project-reactor-essentials-test.git (BARE:master)
$ git push --mirror https://github.com/cuentafulana/clonedRepoTest
Enumerating objects: 603, done.
Counting objects: 100% (603/603), done.
Delta compression using up to 12 threads
Compressing objects: 100% (113/113), done.
Writing objects: 100% (603/603), 128.95 KiB | 18.42 MiB/s, done.
Total 603 (delta 149), reused 603 (delta 149)
remote: Resolving deltas: 100% (149/149), done.
To https://github.com/cuentafulana/clonedRepoTest
* [new branch] master -> master
7.- Remove the temporary local repository you created earlier, If apply.
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ rm -rf project-reactor-essentials-test.git
8.- Check the creation of the mirrored repository in the non original account
9.- Now modify the README.md file to indicate that this repository is a mirrored one.
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ git clone https://github.com/cuentafulana/clonedRepoTest
Cloning into 'clonedRepoTest'...
remote: Enumerating objects: 603, done.
remote: Counting objects: 100% (603/603), done.
remote: Compressing objects: 100% (113/113), done.
Receiremote: Total 603 (delta 149), reused 603 (delta 149), pack-reused 0
Receiving objects: 100% (603/603), 128.95 KiB | 956.00 KiB/s, done.
Resolving deltas: 100% (149/149), done.
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ dir
clonedRepoTest
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab
$ cd clonedRepoTest
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git branch Feature-clone
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git checkout Feature-clone
Switched to branch 'Feature-clone'
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ ls
data.txt pom.xml project-reactor-essentials.iml README.md src/ target/
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ nano README.md
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git add README.md
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git commit -m "this is a mirrored reposiotry in README.md"
[Feature-clone 438d19b] this is a mirrored reposiotry in README.md
1 file changed, 1 insertion(+), 1 deletion(-)
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git status
On branch Feature-clone
nothing to commit, working tree clean
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git remote
origin
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git push
fatal: The current branch Feature-clone has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin Feature-clone
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (Feature-clone)
$ git push --set-upstream origin Feature-clone
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 343 bytes | 343.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote:
remote: Create a pull request for 'Feature-clone' on GitHub by visiting:
remote: https://github.com/cuentafulana/clonedRepoTest/pull/new/Feature-clone
remote:
To https://github.com/cuentafulana/clonedRepoTest
* [new branch] Feature-clone -> Feature-clone
Branch 'Feature-clone' set up to track remote branch 'Feature-clone' from 'origin'.
10.- Now Cloned Mirrored Repository has the new branch feature-clone (2 branches)
11.- Let´s protect the master branch in order that a pull Request is required before merging
12.- Let´s check the difference between branches
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git diff master Feature-clone
diff --git a/README.md b/README.md
index a5a4453..1e4b134 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Project Reactor Essentials Tests
+# Project Reactor Essentials Tests (this is a mirrored Repository)
A Walk through Project Reactor with test
13.- Let´s merge the branch Feature-clone into master
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git merge Feature-clone
Updating d801901..438d19b
Fast-forward
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
14.- Now we can se the change on master - READMEmd file
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ head README.md
# Project Reactor Essentials Tests (this is a mirrored Repository)
A Walk through Project Reactor with test
- Dependencies
- setup Tests
- Mono.just, subscribe(), log()
- subscribe( Consumer, errorConsumer)
- subscribe( Consumer, errorConsumer, CompleteConsumer)
- subscribe( Consumer, errorConsumer, CompleteConsumer, subscriptionConsumer)
15.- Now let´s push the master branch to the repository
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git push -u origin master
Total 0 (delta 0), reused 0 (delta 0)
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: At least 1 approving review is required by reviewers with write access.
To https://github.com/cuentafulana/clonedRepoTest
! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/cuentafulana/clonedRepoTest'
We protect the master branch, so we need a pull Request and approval, so the push is not completed.
16.- Create a Pull Request master <-- Feature-clone
On the another account appears the pull request requiring aproval
ReOpen and Add your review
Review Changes -- Approve
Submit review
Now we can do the push
bext@DESKTOP-NLF0058 MINGW64 /e/CloneRepoLab/clonedRepoTest (master)
$ git push -u origin master
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/cuentafulana/clonedRepoTest
d801901..438d19b master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
In the Account of the cloned Repository the change on the master branch of the README.md file is visible
Other simple operations
$git status
$git branch -a
#create new branch
$git branch new-branch-name
#change environment to the new branch
$git checkout new-branch-name
Git checkout Remote Branch
#create a new branch
$git branch new-branch-name
#change environment to the new branch
$git checkout new-branch-name
#create a change
$touch change.txt
#commit the change
$git add .
$git commit -m "add a new change"
#push to a new branch
$git push --set-upstream origin new-branch
Git Checkout new branch
#fetch all remote branches
$git fetch origin
#list all branches
$git branch -a
#Pull Changes to a Remote Branch
$git checkout -b remote-branch origin/remote-branch
with the remote branch active, do another change
$touch anotherChange.txt
$git add .
$git commit -m "another change"
$git push
git push origin/remote-branch commando was not necessary