美文网首页
Git 初始化本地项目

Git 初始化本地项目

作者: 小伙有点菜 | 来源:发表于2020-03-24 17:10 被阅读0次

Git 初始化本地项目

原创杜兜 最后发布于2018-09-04 21:55:00 阅读数 1073  收藏

展开

  建立 .gitignore文件(定义 Git 提交时要忽略的文件)。一般我们总会有些文件无需纳入 Git 的管理,也不希望它们总出现在未跟踪文件列表。 通常都是些自动生成的文件,比如日志文件,或者编译过程中创建的临时文件等。 在这种情况下,我们可以创建一个名为 .gitignore 的文件,列出要忽略的文件模式。

touch .gitignore

1

  建立 README.md(项目介绍文件)

touch README.md

1

  初始化Git 仓库

git init

1

  添加当前项目的所有文件中有变动的文件添加到本地的暂存区

git add .

1

  查看Git 工作区的状态信息

git status

1

  将暂存区的数据提交到本地仓库,并加入提交的信息

git commit -m "init Git"

1

  Git 提供了一个跳过使用暂存区域的方式, 只要在提交的时候,给 git commit 加上 -a 选项,Git 就会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过 git add 步骤。

git commit -a -m "init Git"

1

  添加远程仓库( 格式为 git remote add [shortname] [url] ),这里origin是为这个远程仓库添加一个引用别名, git@github.com:suinichange/JConcurrency.git 是你GitHub 远程仓库的地址

git remote add origin git@github.com:suinichange/JConcurrency.git

1

  将本地仓库推送到远程仓库,也就是你的GitHub 上

git push -u origin master

1

  执行此命令可能出现的问题:

首次整合远程代码,需要先把远程仓库的代码先拉取下来再提交

报错代码:

To github.com:suinichange/JConcurrency.git

! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'git@github.com:suinichange/JConcurrency.git'

hint: Updates were rejected because the remote contains work that you do

hint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方案:执行  git pull ,再执行 git push -u origin master

1

当前的分支版本落后于远程仓库分支版本

报错代码:

To github.com:suinichange/JConcurrency.git

! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'git@github.com:suinichange/JConcurrency.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方案:如果远程仓库刚创建并没有代码文件,我们可以采取强制覆盖的方式,将本地项目直接覆盖远程仓库项目。

执行 git push -u -f origin master

————————————————

版权声明:本文为CSDN博主「杜兜」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/m0_38069632/article/details/82391117

相关文章

  • 使用git 托管项目到码云

    1.找到项目所在位置初始化本地仓库 2.将本地项目上传到码云,git语句 2.1:git init 初始化本地仓库...

  • 添加github仓库到本地到本地项目

    1.本地项目文件夹下初始化git项目git init2.为本地项目添加别名为 origin 地址为git@gith...

  • 本地代码库合并到远程分支

    1,项目没有git,准备推到指定git地址: git init //本地git初始化 git add . //添加...

  • GIT 提交项目

    一、初始化项目 在项目中初始化git仓库 初始化后会自动创建.git的文件夹,.git文件夹为本地仓库。 到此已经...

  • Git常用命令

    Git本地初始化项目的常用命令 进入要初始化的项目文件夹,执行git init命令 git add . 将工作目...

  • git常用功能

    项目开始: 本地创建文件夹:projectName /projectName git init //初始化git ...

  • git操作经验

    git如何在本地仓库关联远程仓库 本地建立项目 yi-fast,进入目录,初始化本地仓库git init 在git...

  • 把本地项目上传到GitHub

    进入本地项目所在文件夹 1.$ git init //初始化本地仓库 2.$ git add . //如...

  • git命令

    将本地新建的项目提交到远程仓库的步骤 初始化本地仓库git init 将本地内容添加至git本地暂存区中git a...

  • 开发 -- 使用GIT进行本地开发

    Git 本地操作 首先建一个项目目录master(mkdir mater) 初始化git仓库 (git init)...

网友评论

      本文标题:Git 初始化本地项目

      本文链接:https://www.haomeiwen.com/subject/qiqayhtx.html