Let's think about it this way for a moment
The core idea of GitOps is that the git repository should be the single source of truth for the desired state — the cluster's actual state is kept constantly in sync with the YAML in git. If you don't have time yet to install/set up a full GitOps tool (ArgoCD, Flux), you can simulate a basic version with a simple script: a pipeline that clones/pulls the git repository and then runs `kubectl apply -f .`. Understanding this concept gives you a solid foundation for learning tools like ArgoCD/Flux later on.
Let's connect this to a real scenario
Create a `k8s/` folder in your git repository and commit all your deployment/service YAML files into it. When you need to change something, don't edit it directly with `kubectl edit` or through a dashboard — instead, edit the file in git, commit/push it, and then run `kubectl apply -f k8s/` (or let a CI/CD pipeline auto-apply it). This gives you a history/audit trail, and you can roll back cleanly with `git revert`.
Let's look at it together
# Set up a k8s/ folder in your git repo
mkdir k8s
git add k8s/*.yaml
git commit -m "Add web-deployment manifests"
git push
# "Deploy" step — apply everything from the folder
kubectl apply -f k8s/
# Made a mistake? Revert the git commit, then re-apply
git revert HEAD
kubectl apply -f k8s/$ git log --oneline k8s/
a1b2c3d Add web-deployment manifests
$ kubectl apply -f k8s/
deployment.apps/web-deployment configured
service/web-service unchanged5-minute try-it
Commit two or three deployment/service YAML files into a `k8s/` folder, then deliberately commit a mistake (say, a wrong image tag) — fix it with `git revert` and run `kubectl apply` again.
A quick word of caution
This project shows the GitOps concept at its most 'basic' — in production you'd use a tool like ArgoCD/Flux, which brings in auto-sync, drift detection, secret encryption, and more.