Git: How to Commit


If you have made some changes on your website, which has Git installed on it’s server, you will need to commit the changes to the bare repository. This makes sure that everyone who pulls from the Bare repository has the most up-to-date version of the website. This is essential, if you are developing on a local server, and then committing the changes to a live server.

When you have made some changes on your local for example, its always a good thing to check if everything you have done is staged for the commit. You can do this with the command: Git Status.

You will get a list with modified or deleted files or directory’s. Review them carefully, and if there are files that you don’t want to be included in your commit, stash them or put them on a different branch. If you have reviewed all the files that will be committed, you can proceed to the next steps.

1. Before you commit, you need to specify which files will be committed. This can be done in various ways. You can specify per file that you want to add it to the commit, like this:

Git add /local/root/your/directory/index.php

If you reviewed all your files with the tips above, you can also add everything with one command:

Git add .

The . takes all the files that are staged for the commit in one command. Saves you a lot of time if you need to upload a lot of files.

2. Now that you have added all the files that are going to be committed, it is time to make the actual commit. It sounds a lot harder then it is, and it can be done with the following command:

Git commit -m “describe your changes”

The -m stands for Message, and it gives you the option to include a message with your commit. Usually developers describe the changes that are included in the commit, so you can easily find what was changed later on.

3. After you have committed your changes, you want to push them to your Bare repository, so they can be pulled on your live server. Simply type:

Git push

and all the outstanding commits will be pushed to the bare repository. You can then login on your live server and use this command to pull them:

Git pull origin master

With this command you tell Git to pull any changes from the master branch. If you are on an other branch you will need to replace origin master with origin branch name.


Leave A Reply