GitHub的使用总结
目前GitHub非常的火,无论是国内的还是国外的现在都在使用。抽空研究了一下这个东西的使用方法,并总结出来,虽然有一点晚,但是我觉得还是有需要了解和学习的地方。好了,进入主题,一步一步的去介绍,当然最容易的学习方法,当然是跟着github网站提供的步骤去学习。这里我也是针对这个内容来进行总结。
1、github的网址: https://github.com
2、选择login,输入用户名,密码,登陆。登陆之后,就会进入到主页,这里包含了四个基本的应用:
Set Up Git Create A RepositoryFork a RepositoryBe Social3、Set Up a git (主要目的就是在本地系统上安装好git工具,因为github其实是服务于git的网站)git config --global user.name "Your Name Here"# Sets the default name for git to use when you commit
git config --global user.email "your_email@youremail.com"# Sets the default email for git to use when you commit2、补充说明 git的版本查询 git --version git的路径查询 which git4、Create a Repository
mkdir ~/Hello-World# Creates a directory for your project called "Hello-World" in your user directorycd ~/Hello-World# Changes the current working directory to your newly created directorygit init# Sets up the necessary Git files# Initialized empty Git repository in /Users/you/Hello-World/.git/touch README# Creates a file called "README" in your Hello-World directory
git add README# Stages your README file, adding it to the list of files to be committedgit commit -m 'first commit'# Commits your files, adding the message "first commit"
git remote add origin https://github.com/username/Hello-World.git# Creates a remote named "origin" pointing at your GitHub repogit push origin master# Sends your commits in the "master" branch to GitHub
cd Spoon-Knife# Changes the active directory in the prompt to the newly cloned "Spoon-Knife" directorygit remote add upstream https://github.com/octocat/Spoon-Knife.git# Assigns the original repo to a remote called "upstream"git fetch upstream# Pulls in changes not present in your local repository, without modifying your files我的理解,其实就是分支的问题。所谓分支,其实目的是当你需要同时解决两个问题的时候,而这两个问题为了便于后续在合并,因此会创建一个分支,然后在做meiger,将分支合并,从而解决这样的同时存在的问题。
git push origin master# Pushes commits to your remote repo stored on GitHub
git fetch upstream# Fetches any new changes from the original repogit merge upstream/master# Merges any changes fetched into your working files创建分支的方法:
git branch mybranch# Creates a new branch called "mybranch"git checkout mybranch# Makes "mybranch" the active branch其实是实现一个branch,然后将这个branch作为当前获得的branch,进行修改。改变当前branch的方法如下:
git checkout master# Makes "master" the active branchgit checkout mybranch# Makes "mybranch" the active branch两个branch做最后的合并
git checkout master# Makes "master" the active branchgit merge mybranch# Merges the commits from "mybranch" into "master"git branch -d mybranch# Deletes the "mybranch" branch
补充一个关于git的ssh远程访问的配置方法:
首先在本地创建ssh key;
$ ssh-keygen -t rsa -C "your_email@youremail.com"
后面的[email]your_email@youremail.com[/email]改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。为了验证是否成功,在git bash下输入:
$ ssh -T [email]git@github.com[/email]
如果是第一次的会提示是否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,添加远程地址: