Commiting and pushing files from MATLAB to Github using MATLAB script

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

 採用された回答

Luca Ferro
Luca Ferro 2023 年 2 月 7 日
編集済み: Luca Ferro 2023 年 2 月 7 日

0 投票

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 件のコメント

Manoj
Manoj 2023 年 2 月 7 日
@Luca Ferro The file name that I'm setting is a dynamic one and change like below.
How should I pass this inside the system command ?
Below implementation is not working
filePath = 'C:\Users\Projects\data\testFile.xls'
system('git add filePath');
Luca Ferro
Luca Ferro 2023 年 2 月 7 日
f2a=strcat('git add ',{' '} ,filePath); %or if you prefer f2a=['git add' ' ' filePath];
system(f2a)
Manoj
Manoj 2023 年 2 月 7 日
Thanks @Luca Ferro for the quick ans!
Luca Ferro
Luca Ferro 2023 年 2 月 7 日
if you need anything else feel free to ask :)
Manoj
Manoj 2023 年 2 月 8 日
@Luca Ferro getting this error
Luca Ferro
Luca Ferro 2023 年 2 月 8 日
編集済み: Luca Ferro 2023 年 2 月 8 日
what you have put in system() is not a string, you need square brackets [ ]:
[~, gitAdd]= system(['git add' ' ' varargin{1}.filename_PD]);
Manoj
Manoj 2023 年 2 月 8 日
編集済み: Manoj 2023 年 2 月 8 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

質問済み:

2023 年 2 月 7 日

編集済み:

2023 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by