Using Git – typical commands

Committing changes locally

After  you have made some changes  to your local copy you might want to commit them so that they are saved and you can “revert” back to the current state should you ever want to. Each “commit” amounts to a snap shot of the directories which  is saved for all time. You can always revert to the current state.

% git commit -a -m "some note saying what you did"

The “-a” tells to commit all changed files. This is my usual practice. The “-m” adds a memo describing what you changed. If you leave off the “-m” and the comment which follows the system will open an editor (if your system is set up correctly) and you can edit the comments in the editor.

Pushing your changes to the master repository

Once you have committed your changes locally, you have to “push” them to the main repository. This is done with

% git push

If there is an error it is most likely because changes have been made to the main repository since you last updated. You need to perform a “pull” to update your local copy of the repository. You will then often be required to commit again to add the effects of “merging” your local repository   with the main one. Hence a typical “workflow” for committing onese changes is :

% git pull
% git commit -a -m "merges"
% git push

Updating the local repository

This is done by pulling the changes.  Before you can pull you have to commit any changes you have made locally. So although to pull one only needs to say

% git pull

Operationally one usually runs:

% git commit -a -m "my changes"
% git pull


Adding a file to the repository

git only tracts the files you tell it to. To add a new file called “new-file.tex” to version control tracking you would type

% git add  new-file.tex
% git commit -a -m "added the file new-file"

Removing a file from the repository

To remove a file, one types

% git rm  new-file.tex
% git commit -a -m "removed the file new-file"

Of course the file will still be in previous versions and can be recovered at any moment. It will just no longer be in the current version.

Renaming or moving a file in the repository

Renaming is the same as moving.

% git mv  new-file.tex different-name.tex
% git commit -a -m "changed name of new-file"


Leave a Reply

Your email address will not be published. Required fields are marked *