Video Title: Merging Git Repositories
Hello guys today I want to show you how to merge not the ranches but repositories why do you want to merge repositories well let’s say that you are creating two components and at some point you realize this is not actually two separate components I want them
Inside of the same project so what you can do at this point you can for example just take the files and copy them to the second repository and just commit but that will just keep the files the history itself will be lost while in git history is quite valuable
You usually want to save that history and save all the commits from both repositories in one repository or just like me you have a mass in your github because I created like a couple of dozen repositories that I don’t really need and now I want to tidy that up so what I
Will do in this video I’ll take my repository called an old camp and I move it to become a folder in a repository called trainings so what we’ll do I’ll start from cloning trainings repository locally and oops done so let’s clear the screen and now let’s go to trainings
Folder and see what is our remotes remote – V will show me a single remote which is pretty much over satis origin and it’s pointing to my trainings remote and I have a single branch called master right so here’s my branch master and here’s origin master so what is my
Strategy what I want now to do is to add the second remote to this repository the remote that I will add will point to the repository that I want to merge into this one so that’s what I will do first I need to get the URL of that triple
Residual here it is so let’s take the URL and get now to add all this repository sorry this room not camp and at this remote now I want to fetch everything from that remote just to have those commits here locally I will have to do it anyway and after a
Minute they will be here taking a bit slower than I anticipated but it will be here now it is here and I’ve got two remotes let’s check that get remote – we will show me both remotes what I can now do I have two remotes pointing to two different repositories and the single
Working territory so what I can do right now I can just merge from node camp master into my current master and have all the files pulled and then sort them out this will be an easy way to merge and it will indeed preserve all the changes and I can commit afterwards but
What will what will happen is all the files that are present and this repository that I am about to merge they will just be dropped into the root folder I’ll have to make sure that there is no merge conflicts whatsoever so and I might just by mistake when I have all
These files in the same folder together was the file from the other repository just buy me a mistake I might delete or move something that I don’t want to do it him or move so what I want to do is first take all this files and move them
Into the separate folder called node camp in my new repository I’ll do that in a separate branch so I want a new branch I’ll call this branch node camp just like remote and I want to check out North Canton Astra into this branch get branch I’m now on node camp and here’s
My list of files right if I go and check out my master here’s the repository that I’m merging into and here’s my list of files and you see that actually a couple of files are intersecting right if I just do the dummy merge I will have to solve the conflicts which readme was
Licensed I don’t want to deal with that mess so I’m checking out again the new branch that I’ve just created let’s see what we got here the status is obviously clean now I want to create a folder called node camp and I want to move everything to this folder there
Probably is a better way to do that than just typing the commands not very good at that but if you know the better way how to move everything into the subfolder let me know I will be super interested so I’ll move it manually no camp all motor so now I have just a
Single folder called an old camp and the status will show me a bunch of files that I moved there are still really really many of them right so what I can now do I can pretty much safely commit moved all files into a subfolder note
Camp ok now I have two branches and one my branch is master this is the repository that I’m merging to and it has a nice structure this by the way our couple of repositories already merged and I have another branch the old camp that also is much nicer it’s status it
Has just one subfolder and now the merge will be super trivial and go to master I tell that I want to merge with node camp hit done rush conflict and get ignore well hey I skipped get ignore well that’s not a big problem let’s just solve it what
I’ve got here this one I’ll keep these stores okay logs everything else looks pretty much normal what else node modules V and D yeah that’s a good ignore and V and D I’m usually keeping my vendor-specific libraries for JavaScript now git ignore looks okay and I am ready to complete
The merge merged with no camp repository and now both repositories are in the same place here’s my folder structure see so now everything from node camp repo and this nice little folder and now I can push and finally after I push I will clean things up and make sure that
I don’t have any extra branches that I don’t need left now let’s clean up first I want to delete the unused remote I think it is a ram now it can yep and get branch – d node camp want to delete the branch every single oops looks quite nice so I
Am now back in the situation when I have a single repository with a single remote and all my data from the other repository is merged in and the history is also preserved so if I clear the screen and try to do something like graphical look here’s here’s my
Repository that I merged write all the commits ours there they are safe and nice and I have lost nothing now what I can do is finally this node camp is not more required so I go to settings in danger zone and I just say I want to
Delete this Oh North camp I want to delete this repository and I fully understand what I just did so this way we can now just go and check out and trainings here’s my old camp everything is there and the commits from the old camp are also there I hope that this was
Useful see you in the next videos and of course if you have any questions please feel free to leave any comments and subscribe to my channel thank you very much see you later
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
When moving all files to nodecamp folder, losing the history
Which git version you are using here
Or any alternative you can suggest to move files into nodecamp without losing history
This is a great video Juriy
Starts at 1:42 when Juriy starts merging "nodecamp" repository into "trainings"
Hi, Juriy. Awesome video, can you please tell me if the commits remain in history, as an example: I made an complex application in 2021 and I made like 500 commits, do they remain saved in commits history?
I'm having already existing Repository with a directory inside it. So whenever I try to add another Directory to the same Repository using git it gets overwritten, what should I do.
To move everything in new folder without the "fatal: can not move directory into itself", you can use "git mv -k * ./subDir". The "-k" option will simply skip all actions that would produce an error, like trying to move "/subDir" inside itself.
finally, finally and finally I got my solution to my problem. I'm that much happy I can't describe it. I know this problem is not that much big for some guys, but it's really very important for me because I am hustling since last week to find the answer to my query but now from this video, I got my answer. Thanks a lot, sir for this tutorial. I'm really grateful to you. Thank you so much, sir.
Many thanks for this video Juriy!
The following command will move all files and folders to the new folder:
git mv -k * nodecamp/
The -k flag will skip any action that contains an error condition (such as moving the target directory to itself).
You r the best 🙂
Уж и забыл старый дизайн гитхаб, сколько лет уж прошло, Юрец…
Very clear and helpful, even 5 years later! Thank you so much!
Very useful! Thanks 🙂
Btw: the command to select and move all files inside a folder just type "mv * newFolderName" (without quotes).
5:20 when i have to move all files in ./<new-dir> a create one level up a folder : mkdir ../<tmp-dir> ; mv ./* ../<tmp-dir> ; mv ../<tmp-dir> ./<desired-new-dir-name>
Nice video. I performed the same instructions and find it similar to the result you can now obtain (2019) by just doing:
git subtree add –prefix=nodecamp https://github.com/juri/nodecamp.git master
Thank you for the helpful guide/tutorial. I couldn't remember all those commands. So I think it would be useful to sum it up for others here again: 1.) git remote add <RemoteName> <RemoteURL> 2.) git fetch <RemoteName> 3.) check to see whether remote is available with git remote -v 4.) Create a new branch with git checkout -b <NewBranchName> <Branch/master> 5.) move all the files into a subdirectory so there aren't any conflicts with names (git mv) and commit that (git commit -m "moved") 6.) git checkout master 7.) git merge <NewBranchName> –allow-unrelated-histories 7.) cleanup everything with: git remote rm <RemoteName> git branch -d <NewBranchName> 8.) check to see whether everything is correct with: git remote -v git branch -a -v git status 9.) git push
mv $(ls -1a |grep -v nodecamp | grep -vw .) nodecamp
Hi Juriy,
Thanks for the tutorial. It was very helpful and connected the dots I was missing.
Nice tutorial. Many many thanks.
Very useful tutorial. Just little update: since Git v2.9 you have to use: 'git merge bootcamp –allow-unrelated-histories'
HI Juriy,
In Github I have 1 working repository (2 branches Dev/QA) and 1 main repository(multiple branches ) .Main repo is your backbone and from here code goes to UAT.
I need something like pull request between to repository ,so i can compare there branches and merge it to my main repository …
Appreciate your help.
Thanks.
Great video, concepts well explained and a great walk through. Thanks!
Hi Juriy!
I synced the repos successfully by following the steps shown in the video. Is there any way through which we can do the same without making a commit id for the merge operation. In the above method a commit id is generated (I wish if that can be done without that ID).
I explored other methods like post-commit hooks that can be an answer to my query. Any links will be helpful.
Thanks!
Hi Juriy, I don't see the history of nodecamp. For example: https://github.com/Juriy/trainings/commits/master/nodecamp/BookStore.js