Commiting and pushing files from MATLAB to Github using MATLAB script
28 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Luca Ferro
2023-2-7
编辑:Luca Ferro
2023-2-7
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 个评论
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]);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Source Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!