首页 > 解决方案 > 在 github 中创建新仓库后第一次提交 gitignore

问题描述

我在 Github 中创建了一个新的仓库,现在我只想推送 gitignore 文件。在下一次提交时,我想推送其余的文件。

我做的步骤——

> git branch
* master
> git branch -r
> git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   .idea/inspectionProfiles/Project_Default.xml
    new file:   .idea/vcs.xml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   .gitignore
    modified:   .idea/workspace.xml

所以我把.idea/workspace.xmlgitignore 和.idea文件夹一起放进去

> git add .gitignore
> git commit -m 'gitignore only'

我的问题是什么是推送命令,因为远程仓库中没有分支。

非常感谢任何帮助。

更新-1

我尝试了以下 -

git add .gitignore
git commit -m "git ignore only"
git push origin master

现在,当我检查远程 github 时,我可以看到所有文件都已添加。

标签: gitgithub

解决方案


这两个文件已经处于“暂存”状态Project_Default.xmlvcs.xml添加它们.gitignore不会影响在 nextgit commit中它们将被集成到提交中的事实(因为它们是“分阶段的”)。

正如我们在gitignore 文档中看到的那样:“Git 已跟踪的文件不受影响”


推荐阅读