关于git本地仓库和远程仓库(码云)的简单用法
关于git本地仓库和远程仓库(码云)的简单用法
1.首先在码云上创建一个git_demo项目
2.创建之后如下
aaa@qq.com.com:xytg/git_demo.git
我们强烈建议所有的git仓库都有一个README, LICENSE, .gitignore文件
Git入门?查看 帮助 , Visual Studio / TortoiseGit / Eclipse / Xcode 下如何连接本站, 如何导入项目
简易的命令行入门教程:
Git 全局设置:
git config --global user.name "****"
git config --global user.email "****"
**创建 git 仓库**:
mkdir git_demo
cd git_demo
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin aaa@qq.com.com:xytg/git_demo.git
git push -u origin master
已有项目?
cd existing_git_repo
git remote add origin aaa@qq.com.com:xytg/git_demo.git
git push -u origin master
3.接下来我们创建一个IDEA的git_demo,将这个项目所在的文件夹交给git管理
右击文件夹空白页面,进入Git Base Here中输入
git init
交给Git管理后,我们如何才能将IDEA上的git_demo推送到码云上呢??
首先,第一次使用的时候,需要建立连接,这时候上面创建码云项目那段命令都排上出场了
在命令行中输入
**创建 git 仓库**:
mkdir git_demo
cd git_demo
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin aaa@qq.com.com:xytg/git_demo.git
git push -u origin master
git remote add origin aaa@qq.com:xytg/git_demo.git
这一句是将我们本地仓库和远程仓库建立连接(仅第一次输入) git push -u origin master
这是将本地仓库中的git_demo推送到远程仓库(码云),走到这一步已经将README.md文件推送到码云上了
3.我们将IDEA上的推送到码云上
点击push就可以把项目推送到码云上,
点击pull就可以把码云上的数据拉取到项目中
另外分享一个容易出错的地方
本地仓库使用如下命令初始化:
$ git init
之后使用如下命令添加远程库:
$ git remote add origin aaa@qq.com.com:hahah/ftpmanage.git
然后使用
$ git push -u origin master
出现如下错误:
error: src refspec master does not match any.
error: failed to push some refs to 'aaa@qq.com:hahaha/ftpmanage.git'
原因:
本地仓库为空
解决方法:使用如下命令 添加文件;
$ git add readme.txt
添加文件到暂存区
$ git commit -m "init files"
提交到本地仓库
之后在push过程中出现如下错误:
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts.
To aaa@qq.com:hahaha/ftpmanage.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'aaa@qq.com:hahahah/ftpmanage.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 之后在 push
使用如下命令解决:
$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:hahah/ftpmanage
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: init files
继续push,成功。
$ git push -u origin master
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 5.15 KiB | 0 bytes/s, done.
Total 10 (delta 3), reused 0 (delta 0)
To aaa@qq.com:hahaha/ftpmanage.git
a2b5c30..1044f15 master -> master
Branch master set up to track remote branch master from origin.
大功告成!!!
上一篇: git的安装