首先需要在git管理平台(GitHub、码云等等)创建相应的git仓库。
信息填写如下
创建好仓库之后,就可以在开发平台里(本人的开发平台是Windows下的IDEA,不同开发软件不受影响)对git项目进行管理了
具体每一步的命令如下:
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ touch README.md 创建一个READNE.md文件
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ touch .gitignore 创建一个.gitignore文件,把不需要push到git仓库的文件后缀名,添加到文件里
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git init 初始化
Initialized empty Git repository in C:/Users/xujulong/IdeaProjects/GetTheOffer/.git/
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git status 查看状态,看哪些文件有变更
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
.idea/
GetTheOffer.iml
README.md
pom.xml
nothing added to commit but untracked files present (use "git add" to track)
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git add . 添加更新的文件到git
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: .idea/compiler.xml
new file: .idea/inspectionProfiles/Project_Default.xml
new file: .idea/misc.xml
new file: .idea/modules.xml
new file: .idea/vcs.xml
new file: .idea/workspace.xml
new file: GetTheOffer.iml
new file: README.md
new file: pom.xml
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git commit -am 'first commit init project' 提交到本地git,注意只是本地,远程git仓库在下面更新
[master (root-commit) 2fddcad] first commit init project
10 files changed, 448 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/inspectionProfiles/Project_Default.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
create mode 100644 GetTheOffer.iml
create mode 100644 README.md
create mode 100644 pom.xml
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git remote add origin git@github.com:xudachong/get_the_offer.gitgit仓库ssh地址,每个项目不同,视具体而定
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git branch
* master
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git push -u origin master 第一次push,会报错,需要先pull,获取git仓库的内容
To github.com:xudachong/get_the_offer.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xudachong/get_the_offer.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.
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git pull pull,获取git仓库的内容
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:xudachong/get_the_offer
* [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=origin/<branch> master
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git push -u origin master 会再次报错说本地分支不够远程的新,的确如此
To github.com:xudachong/get_the_offer.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xudachong/get_the_offer.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.
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git push -u -f origin master 由于远程git仓库的新建的,没有内容,所以加 -f 强制更新即可
Counting objects: 14, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (14/14), 5.89 KiB | 1.47 MiB/s, done.
Total 14 (delta 0), reused 0 (delta 0)
To github.com:xudachong/get_the_offer.git
+ 94f7563...2fddcad master -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'origin'.
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git branch
* master
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git branch -r
origin/master
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (master)
$ git checkout -b v1.0 origin/master 创建一个分支,因为一般采用分支开发,主干发布
Switched to a new branch 'v1.0'
M .idea/workspace.xml
Branch 'v1.0' set up to track remote branch 'master' from 'origin'.
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (v1.0)
$ git branch
master
* v1.0
@DESKTOP-KJO34F4 MINGW64 ~/IdeaProjects/GetTheOffer (v1.0)
$ git push origin HEAD -u 把分支更新到git仓库
Total 0 (delta 0), reused 0 (delta 0)
To github.com:xudachong/get_the_offer.git
* [new branch] HEAD -> v1.0
Branch 'v1.0' set up to track remote branch 'v1.0' from 'origin'.
接着每次往git放内容,就只需执行下面命令
git branch
git add .
git commit -am 'remarks content' 其中remarks content代表注释内容
git push