Git基本操作

本文详细介绍如何通过命令行创建并初始化Git项目,包括创建项目目录、添加文件、提交更改及将项目推送到远程仓库的过程。同时针对推送失败的情况提供了具体的解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.创建新项目上传

cd parent_dir //进入项目父目录
mkdir gitDemo  //创建项目目录 gitDemo
cd gitDemo //进入项目目录 git init //初始化空的 git 仓库 touch README.md git add README.md //这两行添加简单的 README.md 文件 git commit -m "first commit" //提交时附加的信息 git remote add origin https://coding.net/codingTutorial/gitDemo.git //添加一个名为 origin 的远端( url 为 git 地址) git push -u origin master //将该目录下的文件推送到远端(origin)上的 "master" 分支

可能会遇到的问题

a.如果是首次使用,会提示你先设置好用户名和邮箱,可以在 cmd 中输入:

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

b.git push失败,出现以下提示

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/dummymare/Hello-World.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.

解决方法:

原因:本地版本和主干上的有差异先pull远端的版本,解决了冲突才能push

  git pull -u origin master

然后再

 git push -u origin master

做个小推广:程序员经常久坐,颈椎毛病比较多,特别推荐ventry颈椎保健枕

转载于:https://www.cnblogs.com/longzhongren/p/4307194.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值