首页 > 解决方案 > 任何人都可以从 GitHub“git 教程”中解释这些命令行吗?

问题描述

每次您在 GitHub 上创建新存储库时,它都会向您显示这些我一直觉得有用的命令行...

echo "# Project" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/Username/Project.git
git push -u origin master

但我不知道他们到底在做什么......谁能帮助这个可怜的 Git 新手?

标签: git

解决方案


echo "# Project" >> README.md

这会在您的当前目录中创建一个 README

git init

这将创建一个新的 .git 目录来存储提交和其他对象。

git add README.md

在将文件添加到存储库之前,必须先暂存它。

git commit -m "initial commit"

这会将我们的分阶段更改提交到存储库中。

git branch -M master

使用 -m 或 -M 选项,oldbranch 将被重命名为 newbranch。如果 oldbranch 有相应的 reflog,它会被重命名以匹配 newbranch,并创建一个 reflog 条目来记住分支重命名。如果 newbranch 存在,则必须使用 -M 强制重命名发生

git remote add origin https://github.com/Username/Project.git

这会将远程 url 添加到现有的 git 存储库

git push -u origin master

Push - 将本地更改(或快照)移动/上传到远程 GitLab 存储库

有用的链接: https ://learngitbranching.js.org/ https://doane-ccla.gitbook.io/docs/git-version-control/git-basics


推荐阅读