localhost:mmall czh$ touch README.md localhost:mmall czh$ touch .gitignore localhost:mmall czh$ git init Initialized empty Git repository in /Users/czh/IdeaProjects/mmall/.git/ localhost:mmall czh$ git status On branch master
No commits yet
Untracked files: (use "git add <file>..." to include in what will be committed)
.gitignore README.md pom.xml src/
nothing added to commit but untracked files present (use "git add" to track) localhost:mmall czh$ git add . localhost:mmall czh$ 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 new file: pom.xml new file: src/main/webapp/WEB-INF/web.xml new file: src/main/webapp/index.jsp
localhost:mmall czh$ git push -u origin master The authenticity of host 'github.com (52.74.223.119)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists. localhost:mmall czh$
localhost:.ssh czh$ ssh-keygen -t rsa -C "czh55@qq.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/czh/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/czh/.ssh/id_rsa. Your public key has been saved in /Users/czh/.ssh/id_rsa.pub. The key fingerprint is: SHA256:n5Y9D5wI5LrU/+KgfHnmgRA6+PYAkLMHv/UoOKySSdk czh55@qq.com The key's randomart image is: +---[RSA 2048]----+ | | | . | |= . . | | * . . + | |. B + . S | |.= E + + + * . | |++o = + +.B * | |=. o = oo++. + | |o =. =+o. . | +----[SHA256]-----+ localhost:.ssh czh$ ssh-add ~/.ssh/id_rsa Identity added: /Users/czh/.ssh/id_rsa (/Users/czh/.ssh/id_rsa) localhost:.ssh czh$ ls id_rsa id_rsa.pub known_hosts localhost:.ssh czh$ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfEDYzu0vTLrl2Pve+qJMVJSNffyV2f3suz2khr3X9uT+spxOg+P1TRaBQ3PFjINKfdSJcyCV05+1gv2aeNcLI3wDlui2Us3Rl5fXVRN/YsPOrR6m/RKqSmkpgTKeAE8+HoC3NQggEPZoytOM/L+M3no2PSqkeo/64tRTzWGigWEdGwWN3jeml28pQ+gonziD5OQRGHXlxPlWqDL51B0xhPap/jh8SVCP2mxTJBDuU2xUCoXC/ix87EomTp9bb24aikyyNh2yKtHhpvDK8TpN0gYXxah4yr2b30b8D1A/y2+YwcBPmfnlE+m49D/uzUfQQ9Z8ikgWMoqsXZnSrzlYN czh55@qq.com localhost:.ssh czh$ git config --global gui.encoding utf-8 localhost:.ssh czh$ git config --global core.quotepath off localhost:.ssh czh$ git config user.email czh55@qq.com
再次push到远程:报错(e.g., ‘git pull …’) before pushing again.
1 2 3 4 5 6 7 8 9
localhost:mmall czh$ git push -u origin master To github.com:czh55/imooc.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:czh55/imooc.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.
拉取远程pull
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
localhost:mmall czh$ 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 github.com:czh55/imooc * [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:
第三次push:报错because the tip of your current branch is behind
1 2 3 4 5 6 7 8 9 10
localhost:mmall czh$ git push -u origin master Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts. To github.com:czh55/imooc.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:czh55/imooc.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.
强制覆盖提交到远程
1 2 3 4 5 6 7 8 9 10
localhost:mmall czh$ git push -u -f origin master Counting objects: 11, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (11/11), 1.21 KiB | 414.00 KiB/s, done. Total 11 (delta 0), reused 0 (delta 0) To github.com:czh55/imooc.git + 3ce732e...ae65473 master -> master (forced update) Branch master set up to track remote branch master from origin. localhost:mmall czh$
提交成功
本地创建分支
1 2 3 4 5 6
localhost:mmall czh$ git checkout -b v1.0 origin/master Branch v1.0 set up to track remote branch master from origin. Switched to a new branch 'v1.0' localhost:mmall czh$ git branch master * v1.0
并提交到远程
1 2 3 4 5 6 7
localhost:mmall czh$ git push origin HEAD -u Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts. Total 0 (delta 0), reused 0 (delta 0) To github.com:czh55/imooc.git * [new branch] HEAD -> v1.0 Branch v1.0 set up to track remote branch v1.0 from origin. localhost:mmall czh$