首先到github上面创建一个仓(或者下载其他人创建的也行)。
github新增仓库地址:https://github.com/new
新增仓库默认为空的,复制仓库链接后执行git clone [url]下载到本地
[root@CSDN /home/Sudley/github]#git clone https://github.com/Sudley/git_learning.git
Cloning into 'git_learning'...
warning: You appear to have cloned an empty repository.
[root@CSDN /home/Sudley/github]#ls
git_learning
[root@CSDN /home/Sudley/github]#cd git_learning/
[root@CSDN /home/Sudley/github/git_learning]#ls
[root@CSDN /home/Sudley/github/git_learning]#
将github仓库clone到本地,A表示仓库节点
本地仓库新增bs.html文件
[root@CSDN /home/Sudley/github/git_learning]#vi bs.html
[root@CSDN /home/Sudley/github/git_learning]#git status #查看仓库状态,可以看到新增文件是未跟踪状态
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bs.html
nothing added to commit but untracked files present (use "git add" to track)
[root@CSDN /home/Sudley/github/git_learning]#git add bs.html
[root@CSDN /home/Sudley/github/git_learning]#git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage) #若不想提交此新文件可以使用git rm --cached bs.html移除上面add操作的效果
#
# new file: bs.html
#
[root@CSDN /home/Sudley/github/git_learning]#git commit -m "add bs.html"
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
#to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@bogon.(none)')
[root@CSDN /home/Sudley/github/git_learning]#git config --global user.name ******
[root@CSDN /home/Sudley/github/git_learning]#git config --global user.email ******@**.com
[root@CSDN /home/Sudley/github/git_learning]#git commit -m "add bs.html"
[master (root-commit) 67ffb78] add bs.html
1 file changed, 30 insertions(+)
create mode 100644 bs.html
[root@CSDN /home/Sudley/github/git_learning]#git status
# On branch main
# Your branch is ahead of 'origin/main' by 1 commit. #提示本地分支比远程分支多一个commit
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
[root@CSDN /home/Sudley/github/git_learning]#
此时远程仓和本地仓的节点状态如下,本地的比远程仓多一个节点
git push将本地仓修改推送到远程仓
[root@CSDN /home/Sudley/github/git_learning]#git push
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 757 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/Sudley/git_learning.git
9df625b..cd78fde main -> main
[root@CSDN /home/Sudley/github/git_learning]#git status
# On branch main
nothing to commit, working directory clean
[root@CSDN /home/Sudley/github/git_learning]#
此时查看github上面发现bs.html已添加成功
Tips:新增文件时需要先git add后再commit,如果是修改原文件且一次性提交所有修改则可以使用git commit -am命令替代git add xx和git commit -m。