在linux系统下操作
1:在合适的地方创建一个新的文件夹,我在/usr/local下创建
[root@izq6kip24smlomz ~]# cd /usr/local
[root@izq6kip24smlomz local]# mkdir ssm
[root@izq6kip24smlomz local]# ls
aegis bin cloudmonitor diploma_project etc games gitTest include learngit lib lib64 libexec sbin sh share src ssm test.sh
[root@izq6kip24smlomz local]# cd ssm
2:通过git init命令把文件夹变成git仓库
当出现Initialized empty Git repository in (路径)时代表git仓库创建成功
[root@izq6kip24smlomz ssm]# git init
Initialized empty Git repository in /usr/local/ssm/.git/
Git仓库创建后会有生成一个.git文件夹,不过是隐藏的,可以用ls -a 来查看
[root@izq6kip24smlomz ssm]# ls
[root@izq6kip24smlomz ssm]# ls -a
. .. .git
[root@izq6kip24smlomz ssm]#
3:上传项目到ssm文件夹里
[root@izq6kip24smlomz ssm]# ls
ssm01
用git add 命令添加项目到仓库缓存区
[root@izq6kip24smlomz ssm]# git add ssm01
[root@izq6kip24smlomz ssm]#
添加成功后无提示,可以用git status命令查看当前状态
用git commit 命令提交项目到仓库,-m后面是本次提交的说明,可以为任意内容
[root@izq6kip24smlomz ssm]# git commit -m "ssm01"
[master (root-commit) b06c642] ssm01
296 files changed, 52274 insertions(+)
create mode 100644 ssm01/.idea/artifacts/ssm01_war2.xml
create mode 100644 ssm01/.idea/compiler.xml
create mode 100644 ssm01/.idea/encodings.xml
create mode 100644 ssm01/.idea/misc.xml
create mode 100644 ssm01/.idea/uiDesigner.xml
用git log查看提交日志
[root@izq6kip24smlomz ssm]# git log
commit b06c642f9b1b54667d573c43b724ee54ea0c478e
Author: LYX <1175334569@qq.com>
Date: Fri May 31 10:39:58 2019 +0800
ssm01
4:在github上创建一个新的仓库
创建完成后在Clone or download查看Git链接地址
5:Git关联Github
使用git remote关联到远程仓库
[root@izq6kip24smlomz ssm]# git remote add origin git@github.com:1175334569/ssm.git
[root@izq6kip24smlomz ssm]#
使用git push推送内容到Github
[root@izq6kip24smlomz ssm]# git push -u origin master
To git@github.com:1175334569/ssm.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:1175334569/ssm.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[root@izq6kip24smlomz ssm]#
发生了错误,百度了一下。原来是我在GIthub上创建新的仓库时创建了README.md文件,本地库里没有,所以要先把这文件先下到Git里面,使用git pull --rebase origin master命令
[root@izq6kip24smlomz ssm]# git pull --rebase origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:1175334569/ssm
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
ls
^HApplying: ssm01
[root@izq6kip24smlomz ssm]# ls
README.md ssm01
再次尝试
[root@izq6kip24smlomz ssm]# git push -u origin master
Counting objects: 250, done.
Compressing objects: 100% (231/231), done.
Writing objects: 44% (110/249), 7.63 MiB | 81.00 KiB/s
正在上传,上传完成后就可以在GIthub看到自己的项目了