Github初学使用笔记(本文大部分内容翻译于官网)

Github初学使用笔记(本文大部分内容翻译于官网)

Git 是一个版本控制系统,香港空间,香港虚拟主机,新鲜出炉的。:)Note一下它的使用方法,方便查看…1.安装: 这个不用多说,不同的linux发行版有着各自的打包方式,根据自己的实际情况自行安装. 或者下载最新source code ,编译安装.2.Set up Git: 1)Username 首先你需要告诉git你的名字,这样它才能恰当地标记你创建的commits(means”托管”). $ git config –global user.name “YOUR NAME” #Sets the default name for git to use when you commit 2)Email Git在你创建的commits里保存你的email地址.我们使用email地址来联系你的commits 和你的Github帐号. $ git config –global user.email “your_email@youremail.com” # Sets the default email for git to use when you commit 3)Password caching 这个选项是告诉git你的password的有效时间.(说白了,就是省着总是打密码,默认时间 是15分钟). $ git config –global credential.helper cache # Set git to use the credential memory cache 你可以更改这个时间. $ git config –global credential.helper ‘cache –timeout=3600’ # Set the cache to timeout after 1 hour (setting is in seconds) 3.Create a new Repo on GitHub(仓库:repository) 在GitHub上创建你自己的仓库,都是图形界面,不唠叨. public公共仓库(谁都可以访问)免费; private私有仓库(顾名思义)需要付费. 在这里,我们创建一个Repo,叫做Instance(例子)4.上传你的文件. 是不是迫不及待想上传你的代码了? 别着急,科普一下: GitHub是有本地仓库的概念的. 1)当你编辑好一个文件之后,这个文件是不在你的本地仓库里的.你需要使用命令将其 commit(托管)给git本地仓库. 2)托管给本地仓库之后,再使用命令将其上传到remote server. 这个动作的英文叫做push commit(我理解就是上传托管)—————————————————————— 好了,现在就开始用例子说明问题吧: 1)Create a README file 你编译源码安装软件的时候就会遇到README文件.这个文件用来描述你的project ,或者给你的project添加一些有关安装和使用的文档… $mkdir ~/Instance 特别创建的和仓库Instance同名,方便记忆而已,可以不同. $cd ~/Instance 切换目录,不多说. $git init 设置必须的Git files. $nano README 向这个文件里写点内容,save之后就可以了. 2)Commit your README 下面就是要commit你的文件. 这个动作其实是将你的文件 添加 到本地Repo,还没有上传的. $git add README 将README加入要commit的文件列表. $git commit -m ‘I write a README for testing Git’ Commits your files,同时对你的这次修改添加一个描述. 3)Push your commit 到现在为止,你所做过的所有修改,都已经保存到了你的local repository(本地仓库) 你也明白什么意思,就是你还没上传到GitHub呢. 要想把你的local repo 和你的Github帐号连接,你需要这么做: $git remote add origin https://github.com/username[这个username是你的Github用户名]/Instance.git #创建一个叫做”origin”的远程操作 ,指向你的 Github repo. $git push origin master #Sends your commits in the “master”branch to Github 这里会要求你输入你的GitHub的username and password.5.Fork a Repo 1)Contributing to a project 有时候你会发现你想对某个人的项目作贡献,或者你想使用其他人的项目作为你的起点. 这就是众所周知的”forking” 这里我们用”Spoon-Knife”这个project作为例子. Step1:Fork the “Spoon-Knife” repo click the “Fork” button on GitHub. Step2:Clone your fork 我们成功地将这个项目fork了,但是到目前位置它还只是存在于Github上. 要想使用它作为你的工作起点,你需要将其clone到你的本地机器上. $git clone https://github.com/username/Spoon-Knife.git #username就是你的Github用户名. # Clones your fork of the repo into the current directory in terminal Step3:Configure remotes 当你clone了上面的repo,这个repo被指向一个叫做origin的默认remote(远程操作)上, 而不是原始repo上的那个remote. 为了追踪原始repo,你需要添加另外一个remote叫做upstream. $cd Spoon-Knife $git remote add upstream https://github.com/octocat/Spoon-Knife.git # Assigns the original repo to a remote called “upstream” $git fetch upstream #从远程获取最新版本到本地,不会自动merge(合并). 到这里这些功能,已经够我使用了,毕竟是平时写写练习的程序,只是想找个地方保存一下codeMore things you can do:访问官方网站帮助页 https://help.github.com/articles/fork-a-repo

posted on

,香港服务器怎么能研究出炸药呢?爱迪生不经历上千次的来自失败,怎么能发明电灯呢

Github初学使用笔记(本文大部分内容翻译于官网)

相关文章:

你感兴趣的文章:

标签云: