如何从终端/命令行推送到 git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36890139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:07:35  来源:igfitidea点击:

how to push to git from Terminal / Command Line

gitcommand-lineterminal

提问by sanjihan

I added a file into the folder for Git uploading. I can see the folder in the SourceTree under unstaged. How can I push the file to online storage with terminal commands?

我在文件夹中添加了一个文件用于 Git 上传。我可以在 unstaged 下看到 SourceTree 中的文件夹。如何使用终端命令将文件推送到在线存储?

I figured it out I need to first cd to the local repository, which I did with this:

我发现我需要先 cd 到本地存储库,我是这样做的:

cd /Users/mainuser/Desktop/Projects
git add -A .

checked status with git statusand it outputs this:

检查状态git status并输出:

On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   ios_projects/2016/Untitled copy 2.rtf // this is the file I want to upload

What now? How do I commit it and push it online?

现在怎么办?我如何提交并在线推送?

回答by Shani

next thing would be to commit using and then push to what ever branch you want to push

下一件事是提交使用,然后推送到您想要推送的任何分支

git commit -m 'Some message about the change'

git push origin 'branch-name'

回答by sanjihan

Turns out it is that simple:

事实证明就是这么简单:

cd /Users/mainuser/Desktop/YourFolder
git add -A .
git commit -m 'commit message from terminal'
git push

Edit: if you use just git commitwithout -m, you will enter some editor to type commit message, which I don't know how to quit.

编辑:如果你只使用git commitwithout -m,你会进入一些编辑器来输入提交消息,我不知道如何退出。

回答by Maths RkBala

Try the following cmd:

试试下面的cmd:

$ git status
$ git add <file_name>
$ git commit -m "<msg>"
$ git push origin <branch_name>