github使用

来源:互联网 发布:淘宝网禁止出售的药品 编辑:程序博客网 时间:2024/06/11 22:31

详细教程:

廖雪峰的官方网站

Git是个代码仓库
GitHub是远程仓库,即存在云端的代码仓库

1.第一次创建Git和连接GitHub

1.注册GitHub

首先在本地创建ssh key:ssh-keygen -t rsa -C "your_email@youemail.com" 后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。ssh -T git@github.com如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
# 接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们。$ git config --global user.name "your name"  $ git config --global user.email "your_email@youremail.com"  

进入要上传的仓库,右键git bash,添加远程地址:

$ git remote add origin git@github.com:yourName/yourRepo.git  如果提示出错信息:fatal: remote origin already exists.    解决办法如下:    1、先输入$ git remote rm origin    2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!    3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容    4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc    5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!
  • git add README //添加文件到上传的目录
  • git commit -m “first commit” //提交文件
  • git push origin master//上传到gitHub

git push 命令将本地仓库推送到远程服务器
git pull 命令将远程服务器的仓库clone到本地仓库

-m : 指定说明文字

2.创建版本仓库

mkdir learngitcd learngitpwd  #显示当前目录git init #把这个目录变成Git可以管理的仓库windows下:先新建一个文件(如README.md)再git add README.md #把文件添加进仓库git commit -m "write a readme markdown"# 把文件提交到仓库 -m后面是本次提交的说明,可以输入任意内容,最好是有意义的commit可以一次提交很多文件,所以可以多次add不同的文件git add file1.txtgit add file2.txt file3.txtgit commit -m "add 3 files."从远程仓库克隆:git clone git@github.com:Xxx/yyy.git

3.创建,切换,合并分支

git checkout -b dev  # -b 表示创建并切换相当于:git branch devgit checkout dev# 然后用git branch命令查看当前分支:git branch #当前分支有*号

PS.Git常用命令

hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first merge the remote changes (e.g.,hint: 'git pull') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.可以用 git push --force
0 0