首先从GIT官网(https://git-scm.com/)下载程序安装。
推荐一个GIT教程网站:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
git push错误(fatal: The upstream branch of your current branch does not match)解决方案
查看版本:
$ git --version
git version 2.15.1.windows.2
克隆:
$ git clone git@gitee.com:***********/mmall.git
Cloning into 'mmall'...
remote: Counting objects: 86, done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 86 (delta 38), reused 0 (delta 0)
Receiving objects: 100% (86/86), 22.92 KiB | 45.00 KiB/s, done.
Resolving deltas: 100% (38/38), done.
下面是码云(https://gitee.com/)添加公钥的方法:
Administrator@PC-201701211024 MINGW64 ~/Desktop
$ ssh-keygen -t rsa -C "*********@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)?
Administrator@PC-201701211024 MINGW64 ~/Desktop
$ cat ~/.ssh/id_rsa.pub
ssh-rsa ****B3NzaC1yc2EAAAADAQABAAABAQDhldtejt7jxX0PsiacX3+MKzH0JBMm6k5ro4t27bGkQfrBmc6ICNGUdE6vtw5Itq1KKNi2****HNhDfkr+S79cPmmTakh0DpH7cxmb+QEF759z/JNNfd+VHLe23O1VjljD0LVnrfHNVfUjXZLozVhru4iUPAWIsDQ2AERZI3/In5mKDhJwN/jElhf8DwGIuZ4GZ+sjovvClBJQAvE+X8MVfR/NRsqa1rq2MHhBCY5ul3rKTYtzOxIFvEgaN3Rl8zsB1jhf7xuLFyHHEfaB+qyponeipWCh0lcFreiDxswaT1NOALir3agESYBspK8xC9ZmwEOWkcFyOvBEzklO3yDn *********@qq.com
Administrator@PC-201701211024 MINGW64 ~/Desktop
$ ssh -T git@gitee.com
Welcome to Gitee.com, **!
查看远程分支
$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/v1.0
Git初始化
Administrator@PC-201701211024 MINGW64 /e/git
$ mkdir test
Administrator@PC-201701211024 MINGW64 /e/git
$ cd test
Administrator@PC-201701211024 MINGW64 /e/git/test
$ touch .gitignore
Administrator@PC-201701211024 MINGW64 /e/git/test
$ touch README.md
Administrator@PC-201701211024 MINGW64 /e/git/test
$ git init
Initialized empty Git repository in E:/git/test/.git/
Git Commit
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
README.md
nothing added to commit but untracked files present (use "git add" to track)
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git add .
Administrator@PC-201701211024 MINGW64 /e/git/test (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: README.md
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git commit -am 'first'
[master (root-commit) cd20c72] first
2 files changed, 1 insertion(+)
create mode 100644 .gitignore
create mode 100644 README.md
这个时候还没有远程仓库,现在增加远程仓库。
删除远程仓库:git remote remove origin
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git remote add origin git@gitee.com:***********/test.git
Git push
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git branch
* master
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git branch -r
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git push -u origin master
To gitee.com:lhchanghong/test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:lhchanghong/test.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.
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git pull
warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From gitee.com:lhchanghong/test
* [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
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git push -u -f origin master
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 253 bytes | 253.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To gitee.com:lhchanghong/test.git
+ c085cdc...cd20c72 master -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'origin'.
Git 增加分支
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git checkout -b my origin/master
Switched to a new branch 'my'
Branch 'my' set up to track remote branch 'master' from 'origin'.
Administrator@PC-201701211024 MINGW64 /e/git/test (my)
$ git push origin HEAD -u
Total 0 (delta 0), reused 0 (delta 0)
To gitee.com:lhchanghong/test.git
* [new branch] HEAD -> my
Branch 'my' set up to track remote branch 'my' from 'origin'.
Git 切换分支
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git branch
* master
my
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git checkout my
Switched to branch 'my'
Your branch is up to date with 'origin/my'.
Git 分支合并到master
Administrator@PC-201701211024 MINGW64 /e/git/test (my)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git merge my
Updating cd20c72..87b402f
Fast-forward
test.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 test.txt
Administrator@PC-201701211024 MINGW64 /e/git/test (master)
$ git push
Warning: Permanently added the ECDSA host key for IP address '116.211.167.14' to the list of known hosts.
Total 0 (delta 0), reused 0 (delta 0)
To gitee.com:lhchanghong/test.git
cd20c72..87b402f master -> master
Git 撤销add操作
$ git reset HEAD
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
显示的作者名称
git config --global user.name "name"
git config --global user.email "email"