Can't perform git push/fetch/pull from Command Window

I'm not familiar with Git or GitHub before; my first introduction to these tools are by the integration with MATLAB. I set it up and works well when performing actions through interface (right click on the Current Folder > Source Control > [Action]). I have also set up SSH key so that I don't have to enter my username and password everytime I want to push/fetch/pull. To make the process easier, I want to be able to perform actions through Command Window by starting the command with:
!git ...
However, all actions that require communication with the remote failed, for example:
!git push origin master
What can I do to fix this problem? Thank you!

5 件のコメント

Mario Malic
Mario Malic 2020 年 9 月 6 日
編集済み: Mario Malic 2020 年 9 月 6 日
I don't think that !git status checks the connection with the repository.
Maybe you should try with this
!git push master /origin/master
Adib Yusof
Adib Yusof 2020 年 9 月 6 日
I'm not sure I understand you correctly but the name of the remote, which in my case is 'origin', supposed to be placed after the action right, i.e., 'push'?
By the way I have tried the command you suggested, but it was not succesful either.
Mario Malic
Mario Malic 2020 年 9 月 6 日
編集済み: Mario Malic 2020 年 9 月 6 日
Actually your command is correct.
!git push origin master
I made a test repository and i managed to push it there with this, but I set it up as a project in MATLAB.
You can try to set the repository URL from Remote button, and try to use then the command.
Edit:
  • Check if your RSA key is in .ssh directory
  • See if you get your repository links by this command
!git remote -v
  • Maybe change the commit mail to match the one in your account
!git config --global user.email "email@example.com"
Adib Yusof
Adib Yusof 2020 年 9 月 7 日
Thank you so much for taking time to suggest solutions. I have tried all of them, unfortunately, I was not succesful. I reckon it must have to do my laptop specifically. Until I figure this out, I will continue using the interface to execute git commands. Again, thanks!
Mario Malic
Mario Malic 2020 年 9 月 7 日
The last thing to suggest is to re-do again this guide https://ch.mathworks.com/help/matlab/matlab_prog/set-up-git-source-control.html

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

 採用された回答

Mario Malic
Mario Malic 2020 年 9 月 12 日
編集済み: Mario Malic 2020 年 9 月 23 日

1 投票

Try this as well, this might be the actual solution.
Replace 'username' and 'your-repository'
!git remote set-url origin git@github.com:username/your-repository.git
This will enable you to do do what you want, I had the same issue and this what's fixed it.
In case you commit and push from command window and end up with an error such as this,
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
% Open Git Bash
system('"C:\Program Files\Git\git-bash.exe"'); %wherever is located
%your project path should be current dirrectory, type
git push
% and close Git Bash
Also, commit button from toolbar ignores -S option (GPG signed) in global config.

3 件のコメント

Adib Yusof
Adib Yusof 2020 年 9 月 12 日
Yes, it worked for me, thank you so much!
Mario Malic
Mario Malic 2020 年 9 月 12 日
Glad it did, I learned a little bit about this stuff as well!
Adam Danz
Adam Danz 2020 年 9 月 13 日
+1, me too!

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2020a

質問済み:

2020 年 9 月 6 日

編集済み:

2020 年 9 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by