GitHub学习笔记

简介: 安装Ubuntu上安装Gitsudo apt-get install gitWindows上安装Gitmsysgit是Windows版的Git,从http://msysgit.github.io/下载,然后按默认选项安装即可。安装完成后,在开始菜单里找到”Git”|”Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功!配

安装

Ubuntu上安装Git

sudo apt-get install git

Windows上安装Git

msysgit是Windows版的Git,从http://msysgit.github.io/下载,然后按默认选项安装即可。安装完成后,在开始菜单里找到”Git”|”Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功!

配置

打开命令行,输入如下代码:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"

注意git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

创建仓库

  • 点击GitHub页面右上角的“+”,然后点击“New repository”。
  • 输入仓库的名称及其描述信息。
  • 选择仓库是公开的还是私有的(只允许付费用户创建)。
  • 选择”Initialize this repository with a README.”。
  • 点击”Create repository”。

也可从命令行输入如下语句:
mkdir repoName
cd repoName
git init

提交更新

  • 在仓库的文件列表点击”README.md”。
  • 点击编辑按钮,对文件作出修改,文件内容上方有预览按钮可以预览修改效果。
  • 在”Commit changges”下方输入简单的有意义的更新信息。
  • 点击”Commit changes”。
    最后一步除了”Commit changes”之外还有” Create a new branch for this commit and start a pull request”选项,可以用此选项创建一个pull request。管理员即可点击”Merge pull request”合并结果。如果从命令行合并,步骤如下:
    Step 1: From your project repository, bring in the changes and test.
    git fetch origin
    git checkout -b chinaeagle001-patch-1 origin/chinaeagle001-patch-1
    git merge master
    Step 2: Merge the changes and update on GitHub.
    git checkout master
    git merge --no-ff chinaeagle001-patch-1
    git push origin master

Fork A Repo

创建分支的例子

  • On GitHub, navigate to the octocat/Spoon-Knife repository.
  • Fork buttonIn the top-right corner of the page, click Fork.

同步分支

创建分支的本地克隆。

  • 在GitHub页面,导航到你的分支,复制分支的URL。
  • 打开命令行,输入:git clone https://github.com/YOUR-USERNAME/Spoon-Knife
  • 回车,本地克隆创建完毕。

配置Git使分支与原始的仓库同步

  • On GitHub, navigate to the octocat/Spoon-Knife repository.
  • 复制原始仓库的URL。
  • 在命令行输入git remote -v并点击回车,可以看到当前配置的你的分支的远程仓库。
    git remote -v
    origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

  • 输入git remote add upstream,然后粘贴复制的URL并点击回车。
    git remote add upstream https://github.com/octocat/Spoon-Knife.git

  • 此时,再次输入git remote -v,可以看到如下信息:
    git remote -v
    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
    # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
    # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

现在,就可以通过少量的Git命令使分支与原始仓库同步。
git fetch upstream
git checkout master
git merge upstream/master

The sky’s the limit with the changes you can make to a fork, including:
- Creating branches: Branches allow you to build new features or test out ideas without putting your main project at risk.
- Opening pull requests: If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

目录
相关文章
|
缓存 Shell 网络安全
【GitHub】学习笔记(下)
简介:【GitHub】学习笔记
【GitHub】学习笔记(下)
【GitHub】学习笔记(上)
简介:【GitHub】学习笔记(上)
【GitHub】学习笔记(上)
|
开发工具 git 安全
Github全面学习笔记
不如看看官方的指导手册:https://guides.github.com/ 可以翻译成中文查看哦! ====================================================如何创建分支branch?   分支可以方便同时处理多个版本的代码,它是在创建分支的那个时间点上的原始分支的精确副本。
1071 0
|
开发工具 git Windows
|
6月前
|
程序员 开发工具 git
Github入门10问,收藏~
Github入门10问,收藏~
110 0
|
9月前
|
Shell 网络安全 开发工具
GitHub入门
GitHub入门
98 0
|
开发工具 git
github学习(三)
Git学习(二) 分支学习: 创建新分支dev:git branch dev 切换到dev分支:git checkout dev 可以简写为一句话:git checkout -b dev 可以用命令git branch来查看当前分支的情况。
975 0
|
开发者 C++ 开发工具
github学习(一)
初识github篇。 一.什么是github:       GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub。       github是全球最大的代码托管网站,在这里,你能找到志同道合的朋友,自己的项目可以免费托管在github上,也可以找到很多大公司的开源项目,目前包括阿里,谷歌,苹果等都入驻github,这里也有很多个人开发者的项目,如Mac平台终端配置的"oh my zsh",免费编程资料分享项目"vhf / free-programming-books"等,我自己也经常在github上学习。
1067 0

热门文章

最新文章