Clear Filters
Clear Filters

Commiting and pushing files from MATLAB to Github using MATLAB script

6 views (last 30 days)
Hello All,
I'd like to push a excel file to my github repository(external) that's generated after running a MATLAB script.
I was able to run these below MATLAB commands but not sure how to connect and push to an external github repository
[~, userNameOutput] = system('git config --global user.name');
[~, branchNameOutput] = system('git name-rev --name-only HEAD');
[~, gitCommitSHA] = system('git rev-parse HEAD');
I'm looking something like this Ocktokit library where I can provide auth and commit and push the files using git commands

Accepted Answer

Luca Ferro
Luca Ferro on 7 Feb 2023
Edited: Luca Ferro on 7 Feb 2023
assuming you already cloned your repository in a local directory and already made the checkout of the branches, just move to that directory, add the file, commit your changes and push:
(1)
system('git add <fileName.extension>');
system('git commit -m "<message-to-Commit>"');
system('git push');
if the assumption is not correct, i guess that you have a local branch with no upstream. In this case you can either:
system('git branch --set-upstream-to <remote-branch>') %then add,commit,push
or change the push command in (1) with:
system('git push -u origin local-branch') %git remote -v to find your remotes, the default one is origin usually
Note:
if in (1) you want to programmatically set the name of the excel file refer to this question to get the name of the latest generated file. Then strcat the add command with the name.
Same goes for the commit, just strcat the command and the message together.
  7 Comments
Luca Ferro
Luca Ferro on 8 Feb 2023
Edited: Luca Ferro on 8 Feb 2023
what you have put in system() is not a string, you need square brackets [ ]:
[~, gitAdd]= system(['git add' ' ' varargin{1}.filename_PD]);
Manoj
Manoj on 8 Feb 2023
Edited: Manoj on 8 Feb 2023
Also please let me know if you can help on this qstn
https://in.mathworks.com/matlabcentral/answers/1893275-setting-up-of-port-forwarding-to-postgresql-from-matlab?s_tid=srchtitle

Sign in to comment.

More Answers (0)

Categories

Find more on Source Control Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!