Git basic commands

I have been using git for a while but not to often so as to remember all the commands. The goal the following list is to have a summary of the most frequently used by me Git commands.

Upload to remote repository

The process of updating a remote repository involves the following commands

will return a list of untracked changes

(Dont forget a space between add and the dot)

will add all untracked files, while

will add only the given file

In case there are files to delete from the repo the following command does the trick


will submit the files that have been added so far for upload but it will not upload anything yet.

This finally will update the remote repository.


 Download from remote repository

It is always a good idea before start working on a project to check if there are updates on the remote repository

and then

This will tell whether the local repository is behind.

In that case

will update the local repository


 Exclude files

Typically files which are created as part of compile process and depend on the operating or local system as well as autosaved files should not be uploaded to the remote repository.

To avoid this one can specify rules locally in the file


For example to ignore mex object files we can add *.mex.

There is also the .gitignore option. This is good option when only few files need to be uploaded to the remote repo. One can exclude all files and the include the sources only. See this at the end of the page for example

However the gitignore can be a bit strange in case there are multiple folders in a project and selected files from each folder need to be tracked. Lets say there is a project with 2 folders folder1 folder2 and each folder contains source code with extension *.cpp and *.hpp and other files and folders like CMakeCache.txt CMakeFiles/ etc. and we need to track only the code. The .gitignore should look like this: 



Resolve Conflicts

It is possible that the git push command will refuse to upload the changes. This can happen when two people A and B modify the same file. If A uploads the changes first then git will refuse to push the changes of B.

In that case the B should do the following:

First the git pull –rebase will update the local repository. However there will be some conflicts. The git status command will tell which files contain the conflicts (see more detailed description here). Then B has to edit the files and resolve the conflicts. When its done B need to add the files with git add and finally

will complete the pull and the local branch will ready for git push.



Getting help

Last but not least for every command you can get help using the flag –help e.g.


Leave a Reply

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