Before adding new features, we take a moment to push our code to GitHub. Versioning your work regularly is a good habit: it keeps a clean history, lets you go back if something breaks, and protects the work already done.
Creating the Repository
We use GitHub here, but GitLab or Bitbucket work the same way.
- Click New to create a repository.
- Name: same as the project,
minibib. - Visibility: public, so you can browse the code alongside the videos.
- README: no. .gitignore: no, Symfony already created one. License: not for now.
- Click Create repository.
GitHub then shows every command needed to link a local project.
Linking the Project to GitHub
First, check whether the project already has a remote:
git remote -v
Nothing yet. We add the one GitHub gave us:
git remote add origin https://github.com/<your-username>/minibib.git
git remote -v
# origin https://github.com/<your-username>/minibib.git (fetch)
# origin https://github.com/<your-username>/minibib.git (push)
Staging and Committing
See which files changed:
git status
Add them, either one by one with git add <file>, or all at once:
git add .
git status # the files are now green
Then commit with a short message:
git commit -m "first commit"
Pushing to the main Branch
Check which branch you’re on:
git branch
# * master
GitHub uses main as its default branch. Rather than dealing with master later (when deploying, for example), we rename it now:
git branch -M main
git push origin main
Refresh the repository page: the project is online.
Notice the
vendor/folder isn’t there. That’s on purpose: it’s listed in.gitignore. Never pushvendor/. Anyone can rebuild it withcomposer install.
Recap
git remote add origin <url>links the local project to GitHubgit add .→git commit -m "..."→git push origin maingit branch -M mainrenamesmastertomainvendor/stays out of Git
Exercise · A second commit
Change your home page title, then save that change in a new commit and push it to GitHub. Then check that your history contains two commits.
Show the solution
git status
git add templates/home/index.html.twig
git commit -m "Change the home page title"
git push
git log --oneline
# a1b2c3d Change the home page title
# 9f8e7d6 first commit
Since main is already linked to the server after the first push, a plain git push is enough.
What’s Next
Time for the admin side: we’ll install EasyAdmin.
This is Chapter 4 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.