In the last blog I have explained how you can create a quick login blade component for your demo app. Also said that I will share a trick so you don't have to copy paste all codes in your every project. So let's take a look how we can achieve this.
│ ├── Http
│ │ └── Controllers
│ │ └── Auth
│ │ └── LoginAsDemoLayout.php
│ └── View
│ └── Components
│ └── Demo
│ └── LoginAsController.php
│ └── login-as.blade.php
Why structuring files is important ? Basically when we pull we actually want those specific files to add in our project, which means if your file name matches with existing project files it will not pull instead it will create git conflict. Well this blog is not in-depth about git so I am not going to discuss all. To know more about git you need to do a bit of self study.
- First create a repo in GitHub
- Initialize git, add and commit your files
git add .
git commit -m 'your message'
- connect your git repo
git remote add origin "your git url"
- push your code
git push -u origin main
Now you can pull these files from your any application by simply adding the upstream and pull.
- add upstream
git remote add demo-comp https://github.com/SaaberDev/demo-app-component.git
You might have noticed I added the upstream but instead origin I named it as "demo-comp", why ? Because, we already have an upstream named origin where we are pulling.
- After adding upstream simply use this command to pull.
git pull demo-comp main
Sometimes you may face issue like "refusing to merge unrelated histories" to solve this add
git pull demo-comp main --allow-unrelated-histories
I hope this blog will help you to save your time. From now on you can reuse your code by simply creating a reusable repo and pulling it. This is a simple example but you can use your own technique.