Support article
How to Use Git on Your Hosting: Version Control
Learn to use Git on your hosting to version control your website: clone, commit, sync and work with branches.
Introduction
Git is the world’s most widely used version control system. It lets you keep a history of all changes you make to your website’s code, revert to previous versions and work as a team without stepping on each other.
If you develop websites, plugins or themes, Git is an indispensable tool. And the good news: you can use it directly on your hosting, without needing a VPS. In this article you’ll see how.
What Git is and what it’s for
Git is a system that keeps the history of your code changes. Each time you make an important change, you create a “commit” (a kind of save point). If something goes wrong, you can go back to any previous point.
Its advantages:
- Complete history of all changes.
- Go back to any version.
- Work as a team without stepping on each other’s work.
- Branches to try things without breaking the main version.
- Synchronize with repositories on GitHub, GitLab or Bitbucket.
[Imagen sugerida: diagram of how Git works with commits and branches]
If you develop websites, Git saves you scares. You can always go back to the previous version if something breaks.
Does your hosting have Git?
To use Git on your hosting you need SSH access. On miHosting’s cPanel hosting plans, Git is available.
To check, connect via SSH and type:
git --version
If it shows the version, Git is available.
If you don’t have SSH on your plan, open a ticket. In many cases it can be enabled.
Basic Git concepts
Before starting, these are the concepts you need to know:
| Concept | What it is |
|---|---|
| Repository (repo) | A folder where Git tracks changes |
| Commit | A save point: a specific version of the code |
| Branch | A parallel line of development (for trying things) |
| Clone | Downloading a copy of a remote repository |
| Pull | Bringing remote repository changes to local |
| Push | Uploading local changes to the remote repository |
| Remote | The repository on the internet (GitHub, GitLab, etc.) |
How to start using Git on your hosting
Step 1: Connect via SSH
Connect to your hosting via SSH (see our guide on how to connect via SSH to your shared hosting).
Step 2: Go to your website’s folder
cd public_html
Change
public_htmlto the folder where your website is if it’s elsewhere.
Step 3: Initialize Git
If you want to start a new repository in an existing folder:
git init
This creates an empty Git repository in that folder.
Step 4: Clone an existing repository
If you already have your website on GitHub, GitLab or Bitbucket and want to bring it to hosting:
git clone https://github.com/user/mywebsite.git
[Imagen sugerida: screenshot of the git clone command in the terminal]
For private repositories, it will ask for username and password (or access token).
Basic Git workflow
See what you’ve changed
git status
It shows which files you’ve modified since the last commit.
Add changes to the commit
git add . # add all changes
git add index.php # add only one file
Create a commit
git commit -m "Homepage header change"
The commit message should describe what you’ve changed. Being clear helps find changes later.
Upload changes to the remote repository
git push origin main
This uploads your commits to the repository on GitHub (or wherever you have it).
Bring changes from the remote repository
If someone else has made changes (or you from another computer):
git pull origin main
Working with branches
Branches let you make changes without affecting the main version. Very useful for trying things.
Create a branch
git checkout -b new-feature
Switch branches
git checkout main # return to main branch
git checkout new-feature # return to new branch
Merge a branch with main
When you’ve finished changes in the branch and want to bring them to main:
git checkout main
git merge new-feature
How to sync your hosting with GitHub
The most common is to have the repository on GitHub and have your hosting sync with it. There are two ways:
Option 1: Manual pull
Each time you want to update your website on hosting, connect via SSH and do:
cd public_html
git pull origin main
Option 2: Automatic deployment
Configure a webhook on GitHub so that, when you push, GitHub notifies your hosting and it updates itself. Requires a bit more configuration.
For most projects, manual pull is sufficient. Automatic deployment is used in projects with many daily deployments.
How to ignore files with .gitignore
There are files you don’t want to upload to the repository (for security or because they don’t contribute):
- Configuration files with passwords (
wp-config.php). - The WordPress
uploadsfolder. - The database.
Create a .gitignore file in the repository root:
wp-config.php
/wp-content/uploads/
*.log
.env
Everything you put there won’t be uploaded to the repository.
Useful tips
- Never upload passwords to Git. Use
.gitignorefor files with sensitive data. - Make small, frequent commits. It’s easier to go back.
- Write clear commit messages. “Fixed checkout bug” is better than “changes”.
- Before a push, test locally. Don’t upload code without testing.
- Use branches for experimental things. Don’t work directly in
main.
Common problems
”fatal: not a git repository”
You’re trying to use Git in a folder that has no repository. Run git init or go to the correct folder.
Pull fails due to conflicts
Someone has modified the same files as you. Git doesn’t know which version to keep. You have to resolve the conflict by hand: open the file, choose which version to keep and make a new commit.
Git asks for username and password every time
Configure your credentials to be saved:
git config credential.helper store
Or use SSH keys instead of HTTPS to authenticate.
I made a commit and made a mistake
If you haven’t pushed yet, you can undo the commit:
git reset HEAD~1
This undoes the last commit but keeps the changes in the files.
My repository is very heavy
It may be that you’re uploading large files (images, videos). Review your .gitignore and consider not uploading binaries to the repository.
Frequently asked questions
Is Git installed on my hosting?
If you have SSH access, most likely yes. Check with git --version.
Do I need GitHub to use Git?
No. Git works perfectly on its own locally. GitHub is just a place to store the repository remotely, to share or sync.
Can I use Git with WordPress?
Yes. In fact, it’s highly recommended for theme and plugin developers. Just make sure to exclude wp-config.php and uploads/ in .gitignore.
Does Git affect my website’s performance?
No. Git only keeps the history in a hidden folder (.git). The website works the same.
Can I have several repositories on the same hosting?
Yes, one per folder or domain.
Control your changes with Git
Git is the number one professional web development tool. It lets you have a complete change history, go back when something fails and work as a team without problems. And you can use it directly on your hosting, without needing a VPS.
If you need help configuring Git on your miHosting hosting, open a ticket from your client panel. And if your project needs a more advanced environment with automatic deployments, our managed VPS are the ideal option.