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.

Contents

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

while

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

.git/info/exclude

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.


 

Find the remote URL

 

Getting help

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

2 thoughts on “Git basic commands

  1. Hi Dr George,
    I am supervising a master degree student and she has been asked to use mSim for her thesis. We are planning to replace your optimizer with another evolutionary optimizer. Another colleague of mine is doing her PhD in groundwater modelling. Can we use mSim for recharge estimation for a large aquifer of about 100000 km2 area? If we want to carry out seawater intrusion studies for this large aquifer and want to calibrate the mSim, how do we do that? If you could suggest us and direct us to use mSim for calibration, then coauthorship in the resulting publication is possible in case you agree.

    Thanking you.

    Regards,

    Surajit

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.