Github Upload on Mac OS, Common Operation and Trouble Shooting Records

本文参考:https://blog.csdn.net/yyh352091626/article/details/50714880

下载Github

http://git-scm.com/downloads

 

创建SSH

cd ~/.ssh

若文件不存在:

ssh-keygen -t rsa -C xxx@xx.com

xxx@xx.com是github注册邮箱

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/yuyuhang/.ssh/id_rsa):       // .ssh默认路径,不输入则不修改
Enter passphrase (empty for no passphrase):                              // 密码长度至少为4,否则失败(1234)
Enter same passphrase again: 
Your identification has been saved in /Users/yuyuhang/.ssh/id_rsa.
Your public key has been saved in /Users/yuyuhang/.ssh/id_rsa.pub.
The key fingerprint is:
8d:d3:5f:31:ae:13:48:f0:78:df:a1:8f:a5:a4:c0:06 352091626@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
|        .        |
|         +       |
|      E . +   +  |
|       o * o + + |
|        S + = =  |
|       . o + O   |
|          . * .  |
|             .   |
|                 |
+-----------------+

接下来就是在GitHub上创建SSH:登录GitHub,右上角用户头像下选择Settings,在SSH Keys 选项里面添加ssh。

Title:xxx@xx.com
Key:打开你生成的id_rsa.pub文件(/User/yourname/.ssh/is_rsa.pub),将其中内容拷贝过来。

显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES

隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO

 

创建Github Repository

GitHub首页,点击“Create a New Repository”,创建时,README.md这步暂不勾选。

 

创建本地仓库

touch README.md                                         //新建一个README文档,若上一步勾选了创建README.md,提交时导致冲突
git init                                                //初始化本地仓库
git add README.md                                       //添加刚刚创建的README文档
git commit -m "你的注释...."                             //提交到本地仓库,并写一些注释
git remote add origin git@github.com:yourname/xxxx.git  //连接远程仓库并建了一个名叫:origin的别名,当然可以为其他名字,但是origin一看就知道是别名,youname记得替换成你的用户名
git push -u origin master                              //将本地仓库的文件提交到别名为origin的地址的master分支下,-u为第一次提交,需要创建master分支,下次就不需要了

 

上传代码

git add foder1                                      // 添加需要提交的文件夹,使用git add .  则添加全部
git add file1
...
git commit -m "upload source code"                   // 提交到本地仓库
git remote add origin git@github.com:xxx/xxx.git // 增加一个远程服务器的别名。
git remote rm xxx // 删除远程版本库的别名

git push origin master // 将本地仓库合并到别名为origin地址的master分支下

 

刷新一下GitHub,则显示刚刚提交的项目源代码。

 

删除文件

git pull
git rm -rf Folder1 git commit -m “Folder1 deleted” git push

 

Trouble Shooting

error: failed to push some refs to 'git@github.com:linnvel/text-classifier-master.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.

Solution:

Try

git push origin master --force

Or short of force -f

git push origin master -f

Instead of 

git push -u origin master 

同步代码到本地:

git clone git://github.com:xxxx/test.git //以gitreadonly方式克隆到本地,只可以读
git clone git@github.com:xxx/test.git  //以SSH方式克隆到本地,可以读写
git clone https://github.com/xxx/test.git //以https方式克隆到本地,可以读写
git fetch git@github.com:xxx/xxx.git  //获取到本地但不合并
git pull git@github.com:xxx/xxx.git //获取并合并内容到本地

 

 下载某个分支

git clone -b b1 https://github.com/...

 

下载所有分支

git clone https://github.com/...
git branch -r
git checkout b1

 

More operation:

https://blog.csdn.net/five3/article/details/8904635 

git add -u : exclude untracked files

https://blog.csdn.net/leorx01/article/details/72358401

git reset : remove all added files

posted @ 2020-04-07 13:15  Sherrrry  阅读(188)  评论(0编辑  收藏  举报