使用git上传项目至github

首次上传

   在上传知之前要做的工作:
    1.安装git,
    2.安装完成后,找到要上传的文件所在的文件夹,鼠标右键选择 git bash here
    3.首先在本地创建ssh key:在 $ ssh-keygen -t rsa -C "your_email@youremail.com";生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
    4.注册一个github账号,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。,
    5.验证是否成功:$ ssh -T git@github.com 。如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
    6.配置git:
        $ git config --global user.name "your name" 
        $ git config --global user.name "your name"$ git config --global user.email "your_email@youremail.com"
    7.建立一个repository:Create a New Repository ;
    这是要准备的工作。
    首次上传:
    1.$ git add README
    2.$ git commit -m "first commit" 
    3.$ git remote add origin git@github.com:yourName/yourRepo.git,git@github.com:yourName/yourRepo.git是你创建的Repository的地址。
    4.$ git push origin master 
    
    再次上传文件时,如果上传的时之前没有上传的文件,重复首次上传的步骤即可。如果是要把已经上传的文件修改后再次上传,要按下面的步骤来:
   1.$ git add README
   2.$ git pull
   3. $ git commit -a '注释'
   4.$ git push -u origin master

git pull和本地文件冲突

当git pull和本地文件冲突时会报fatal: refusing to merge unrelated histories这个错误。
在网上找了很久,找到一个方法:具体步骤如下:
1.git add 要修改的文件
2.git pull origin master --allow-unrelated-histories  
3.git status
4. git commit -am '注释'
5.$ git push -u origin master
原文地址:https://www.cnblogs.com/rainbow8590/p/7127652.html