下次不要再忘了
虽然一直都在使用Github,但是经常不常用命令行都容易忘记掉,特意在此进行一次记录。
1、在GitHub创建一个项目
2、在本地文件夹中,做一次Git初始化
~/Aliyun/alioss ⌚ 17:27:15
$ git init
Initialized empty Git repository in /Users/wangdong/Aliyun/alioss/.git/
3、将所有文件都添加到Git中
~/Aliyun/alioss on master! ⌚ 17:27:24
$ git add .
4、将 Git中的地址复制出来
5、本地项目和远程的GitHub关联起来
~/Aliyun/alioss on master! ⌚ 17:28:54
$ git remote add xiongben-tongxue https://github.com/xiongben-tongxue/alioss-demo.git
6、现在如果执行git push的话,就会报错
~/Aliyun/alioss on master! ⌚ 17:29:18
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
7、那么看看状态吧
~/Aliyun/alioss on master! ⌚ 17:31:06
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: .mvn/wrapper/maven-wrapper.jar
new file: .mvn/wrapper/maven-wrapper.properties
new file: conf/log4j.properties
new file: mvnw
new file: mvnw.cmd
new file: pom.xml
8、需要先添加文件,再提交文件
~/Aliyun/alioss on master! ⌚ 17:31:15
$ git add -A
~/Aliyun/alioss on master! ⌚ 17:31:19
$ git commit -m "修复文件上传到github"
[master (root-commit) 79e296b] 修复文件上传到github
25 files changed, 1708 insertions(+)
create mode 100644 .gitignore
create mode 100644 .mvn/wrapper/maven-wrapper.jar
create mode 100644 .mvn/wrapper/maven-wrapper.properties
create mode 100755 conf/log4j.properties
create mode 100755 mvnw
create mode 100644 mvnw.cmd
create mode 100644 pom.xml
9、再git pull一下
~/Aliyun/alioss on master ⌚ 17:31:39
$ git pull
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 https://github.com/xiongben-tongxue/alioss-demo
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> master
10、分支关联
~/Aliyun/alioss on master ⌚ 17:42:35
$ git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.
11、git pull报错
~/Aliyun/alioss on master ⌚ 17:43:53
$ git pull
fatal: refusing to merge unrelated histories
12、git push报错
~/Aliyun/alioss on master ⌚ 17:49:17
$ git push
To https://github.com/xiongben-tongxue/alioss-demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xiongben-tongxue/alioss-demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
13、原因是git pull需要允许拉取在GitHub上创建的不相关联的文件
~/Aliyun/alioss on master ⌚ 17:49:43
$ git pull origin master --allow-unrelated-histories
From https://github.com/xiongben-tongxue/alioss-demo
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
14、最后再Git push 就成功了
~/Aliyun/alioss on master ⌚ 17:50:09
$ git push
Counting objects: 52, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (52/52), 60.60 KiB | 8.66 MiB/s, done.
Total 52 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/xiongben-tongxue/alioss-demo.git
a6023fd..b3c0fcc master -> master