Store git command result into a variable using MATLAB script


I’m trying to get the result after executing the git command function !git config --global which outputs my username in the command prompt of my MATLAB.

Now if I assign the same to a variable to use it in another instance I’m getting the below error as shown below.

userName = !git config --global

Error : Parse error at !git config --global : Usage might be invalid MATLAB syntax



You will need something like

[~, out.git_hash] = system('git rev-parse --verify HEAD');
[~, out.git_status] = system('git --no-pager diff --no-color');


On Windows, depending on different options during setup, you may need to supply the full path to the git binary, e.g.

[~, out.git_hash] = system('"C:/Program Files/Git/mingw64/bin/git"  rev-parse --verify HEAD'); 
[~, out.git_status] = system('"C:/Program Files/Git/mingw64/bin/git" --no-pager diff --no-color'); 

Just be cautious with pager-related parameters.

Answered By – X Zhang

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published