git 简明教程(1) --创建及提交

本文提供了一次性入门的Git命令行操作教程,包括账号注册、仓库创建、文件管理、远程同步等核心步骤,适合初学者快速上手。

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

本文对 通过命令行进行 git 操作做简单 总结。


建立git

1.登录github官网完成注册。并下载git客户端。

2.为本机配置 git的用户名和 密码。

Username

First you need to tell git your name, so that it can properly label the commits you make.

git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit

Email

Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

git config --global user.email "your_email@example.com"
# Sets the default email for git to use when you commit


创建仓库 repository
1. 在github官网 创建 reponsitory -- hello-world
2. 本地建立相应文件夹 
 
mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory

cd ~/Hello-World
# Changes the current working directory to your newly created directory

git init
# Sets up the necessary Git files
# Initialized empty Git repository in /Users/you/Hello-World/.git/

touch README
# Creates a file called "README" in your Hello-World directory     打开README 写入文本"hello,world"

3.commit 
git add README
# Stages your README file, adding it to the list of files to be committed

git commit -m 'first commit'
# Commits your files, adding the message "first commit"

此时完成了本地的 索引加载与提交,并未与 github 有任何联系,下面完成与 github的数据更新

4. push
首先在远端 建立一个连接,然后推送你的提交
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repository

git push origin master
# Sends your commits in the "master" branch to GitHub

以上为官网的做法,存在问题。

问题一:error: The requested URL returned error: 403.... fatal: remote re-origin already exists.
原因 git目前 http支持的不太好,或者说暂时不能用(个人不确定阿)。
解决方法:改用 ssh方法 来连接

git remote add re-origin git@github.com:usrname/Hello-World.git

问题二:
error: failed to push some refs to...Merge the remote changes before pushing again.
应先远端获取最新版本,然后提交,防止冲突
git pull origin master //从远端 origin获取最新版本到本地master中
git commit -am "update .."
git push origin master //向远端推送

此时打开 github相应 仓库 即可开到上传的文件。


简单总结
1.远端建立 reponsitory
2.本地建立相应文件并进入
3.编辑本地文件
$ git init //
$ git add . //完成对添加文件的索引
$ git commit -am 'init commit.' //本地提交
$ git remote add origin git@github.com:username/username.github.com //本地与远端建立关系 ,通过ssh方式
$ git pull origin master //从远端 origin获取最新版本到本地master中

  

  
$ git commit -am "update .."
$ git push origin master //向远端推送 完成简单的创建与 远端提交

参考此处 create a reponsitory

如有错误和意见,请大家指出,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值