GitHub使用方法

git下载地址:https://git-scm.com/downloads 下一步下一步就好了

在cmd输入 git --version

在桌面空白右键 Git Bash Here命令行

输入 git --version

在https://github.com/注册一个账号  

 

 配置sshkey

cd ~/.ssh

ll 查看下所有的目录

进入命令  cd /

ssh-keygen -t rsa -C "1341376695@qq.com"一直回车,不用管

ll

下面多了2个文件

pwd

cat id_rsa.pub

查看复制

 title随便起个什么名字就好

2.配置多个sshkey

cd ~/.ssh

vim config 没有的话,vim就创建了一个

Host github.com

HostName github.com

User  这个就是user填写的地址

 

 IdentityFile 填写的是id_rsa的绝对路径

3.在gitup创建项目

 

  打开命令行

mkdir muke

cd muke

git clone git@github.com:xuzhongtao/test1.git 仓库克隆到本地

cd AutoTest 进入仓库

vim test.txt

输入一些内容

cat test.txt

git status 查看本地仓库文件状态

git add test.txt报错

解决办法:

$ rm -rf .git  // 删除.git  
$ git config --global core.autocrlf false  //禁用自动转换    

然后重新执行:

$ git init    
$ git add 文件名

it中报unable to auto-detect email address 错误的解决拌办法

昨天刚配置好的git,今天刚要commit一些修改,就遇到了这个问题
** Please tell me who you are.


Run


  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"


to set your account's default identity.
Omit --global to set the identity only in this repository.


fatal: unable to auto-detect email address (got 'tim@newton.(none)')


后来找到了解决办法:
找到工程目录的.git文件夹,打开之后找到config文件,在最后边加上一句话
[user]
 email=your email
 name=your name
your email 和your name随便写上就行
-------------------------------------------------------------------------------------

git status   

git commit -m "增加测试文件"   增加本次提交文件的说明 回车

git push 推送到gitup网站上 

报错

fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

git remote add <name> <url>

and then push using the remote name

.或在命令行上创建一个新的存储库

git init 
git add README.md 
git commit -m“first commit” 
git remote add origin https://github.com/xuzhongtao/test1.git
git push -u origin master

...或从命令行推送现有存储库

git remote add origin https://github.com/xuzhongtao/test1.git
git push -u origin master

-------------------------------------------------------------------------

git pull  拉取

4.项目分支

git branch 查看本地分支

git branch -a 查看远程端的分支明令   多了一行

git checkout  -b branch1                 在本地创建分支

vim test.text 编辑这个文件

保存 退出

git add test.txt

git commit  -m  "提交到分支1的内容"

git push  提交

git push --set-upstream origin branch1

 5.分支操作--删除分支

git branch -d branch1 删除本地分支 不能删除自已使用得分支

git checkout master  切换master

git branch -r -d origin/branch1 删除远程的分支

git push origin :branch1    origin后面有一个空格  删除远程的分支

6.git合并分支

git checkout -b mergedemo  创建一个分支

git merge mergedemo 合并分支

7.git项目操作

git   add . 更新所有的文件 

git reset --hard HEAD^ 回退到上一个版本

git reset --hard HEAD^ 回退到上上一个版本

git reset --hard HEAD~100  回退到上100一个版本

git reflog  版本的id号

git reset --hard 657a18  通过id号指定哪个版本

 ----------------------------------------------------------------------------------------------

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.

解决办法:

$ git pull origin master
$ git push origin master

--------------------------------------------------------------------------------------------------------------

解决方法

可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin master
posted @ 2018-12-09 19:59  taotao12  阅读(326)  评论(0编辑  收藏  举报