Git 本地存储库所有步骤

Git Local Repository All Steps

我在 git 中为零。绝对零度。所以网上有很多资料和提示,但是我不能把它们放在一起。

那么有人可以告诉我我做错了什么以及我还应该做些什么来实现我正在寻找的东西吗?

我想做的很简单。我用 C++ 编写了一个项目,现在我想创建一个本地存储库来对我的所有更改进行版本控制。这就是我所需要的。

我有一个文件夹:

~/myproject

其中包含我的项目文件。和另一个用于保存更改的文件夹(我本地存储更改的位置)

~/my-local-repository

所以,首先,我已经建立了一个回购协议:

cd ~/myproject
git init

然后我创建了一个 .gitignore :

cd ~/myproject
touch .git/.gitignore

并排除了我的 bin 目录。

然后我添加了几个文件

git add this that

然后我删除了它们

git reset

并再次添加了一些文件。我更改了一些文件并提交:

git commit -am "new change"

然后设置虚拟用户名和电子邮件:

git config user.name "my.phd"
git config user.email myphd@exmaple.com

然后我为本地更改设置本地存储库文件夹:

git remote add local ~/my-local-repository

所以我希望我的所有更改都放在这里。

现在,当我按下时:

git push local

我收到这个错误:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

fatal: '/media/doc/my-local-repository' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

也许这个错误对很多人来说很简单。但我对此一无所知。到目前为止我做错了什么以及如何解决?

错误在线

'/media/doc/my-local-repository' does not appear to be a git repository

该文件夹中没有 git 存储库。你需要运行

git init

在里面。如果您在一个新的本地分支中工作,您还必须将该新分支向上游推送以使其出现在远程中。为此,请参阅 this 问题。

git push local master(或者,而不是 master,您要推送的分支)

如果你只对另一个仓库做了 git init,它还没有分支。因此,无法跟踪任何分支(只允许 git push local)。

执行此命令后,不需要在末尾 master,因为 master 现在存在于 local