Git——新手入门与上传项目到远程仓库GitHub


Git概述

Git:是目前世界上最先进的分布式版本控制系统,一个开源式的分布式版本控制工具。

简单浅显地来说(就我个人而言),就是一个全球程序员的代码仓库集中地,每个人都可以在这里拥有一个自己的小仓库(注册一个独立的账号就可以了),你的代码可以一件一件的保存在这里,也可以分享给全球的程序猿同类们,所以即使你在本地对自己的项目随意删改(哪怕它爆炸~-~)都是可以通过Git从GitHub上传回之前提交的代码,做到有备无患。

同时,它能够记录每一次的版本改变,这个不用我多说大概各位也能猜到了,在以后工作中如果进行协同版本控制也离不开Git的帮助了。

Git安装

在Windows操作系统下,访问Git下载地址https://git-for-windows.github.io/,如果登不进去的话直接百度搜索Git下载也是可以的.


id="iframe_0.7693696282605178" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3803/a9c9a133-be91-3752-b0ad-2a7921084902.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7693696282605178',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 584px; height: 247px;">

安装过程不赘述了,指定好安装目录就好,完成之后能在菜单看到.


id="iframe_0.0047205855712615374" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3805/a2943bd9-4b87-3aa4-9469-69f6c2dd7c09.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.0047205855712615374',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 249px; height: 87px;">


 创建本地代码仓库

 打开Git Bash

首先配置自己的身份,这样在提交代码的时候就能知道是谁提交的

输入git config --global user.name "名字"

git config --global user.email "邮箱地址"

配置完成之后可以查看自己的邮箱地址和名字,比如我的是


id="iframe_0.4399951480585962" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3807/ebc7d717-b920-31e1-90d5-fa54c4ead402.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4399951480585962',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 299px; height: 60px;">


id="iframe_0.46801995876664093" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3809/d3428a55-6a33-3076-ba76-cd524b8580a8.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.46801995876664093',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 308px; height: 60px;">

然后开始创建代码仓库,这里以测试项目helloworld为例

 

 输入git init就可以创建啦~

然后使用ls -al查询代码仓库,如果想删除这个仓库,直接从目录下删除这个文件夹就可以了..
id="iframe_0.6608905326476542" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3815/508ea613-5782-3533-a2c7-be031c6d4fef.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6608905326476542',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 580px; height: 397px;">
 提交本地代码

仓库建立完成之后就可以提交本地代码了,这里只需要用到两个命令,add添加和commit提交

add .是提交所有(注意这里有空格add和.之间)

add +文件名是提交单个文件

git commit -m "First commit"是提交这里要在-m参数后面加上提交参数,很重要哟,不然会被认为不合法不能提交.


id="iframe_0.837988572598839" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3817/ef34810a-bf10-3335-9783-8ae82d528fd6.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.837988572598839',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 580px; height: 523px;">
 入门工作就介绍到这里了,之后的功能例如分支,协作远程版本库,查看记录以及提交记录,都可以直接去找Git的命令使用就可以了,并不困难。

******************************************************南瓜的分割线************************************************************

 

 创建GitHub账户以及托管本地代码

进入官网,点击Sign up for GitHub注册

https://github.com/

id="iframe_0.578470038804433" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3819/2447b71c-64dc-360e-b66b-0958847eacce.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.578470038804433',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 1017px; height: 512px;">
 

接着点击New repository新建版本库,


id="iframe_0.46096387239674375" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3825/a00c6757-5f05-3f8f-aa72-367251289925.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.46096387239674375',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 683px; height: 566px;">
 

点击create repository按钮,之后会显示你的版本库主页


id="iframe_0.6284919083270877" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3823/523a64df-e339-3ed2-9723-7b24a7f73952.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6284919083270877',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 820px; height: 551px;">
 之后获取远程版本库的地址,非常重要


id="iframe_0.8659355413300935" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3827/07c14f61-1db8-386c-b5d5-a9dbbc734d9a.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8659355413300935',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 505px; height: 282px;">

然后打开Gitbash

切换到helloworld工程目录下,把远程版本库克隆到本地

有时候会传输超时。。就再试几次。。


id="iframe_0.9490683486020026" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3829/fb61b3c3-16a7-3b30-976d-ea0da6ee739d.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9490683486020026',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 513px; height: 100px;">

这个时候你的工程目录下会多出一个helloworld文件夹,把这个文件夹里的所有目录复制到上一层目录中,就能将整个工程添加到版本控制中去了
 
id="iframe_0.23792218595223957" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3831/4b0231b8-05ed-36b7-8ffc-9de7f96a310a.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.23792218595223957',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 728px; height: 220px;">
 这里这里有个隐藏的.git文件,不要漏掉!!!

复制完之后可以删掉helloworld目录,之后ls -al查看工程目录


id="iframe_0.4274195874844591" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3833/2fe41a25-5695-3f80-8913-e826fd39b861.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.4274195874844591',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 513px; height: 260px;">
 然后就是提交到Github上面的工作了!!!

先执行提交操作,然后输入 git push origin master同步

注意这里要记得输入用户名和密码进行身份效验!!切记!不要以为它不动了。。

输入密码的时候不会显示。。但是输完回车就行了。

过程可能比较慢,耐心等待,也有可能是我的校园网有毒..


id="iframe_0.318390981159" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0112/3835/acff447b-f864-3e08-88c2-213a2434b056.png?_=5486278%22%20style=%22border:none;max-width:1017px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.318390981159',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 476px; height: 146px;">
 现在刷新一下GitHub上helloworld工程的版本主页

你已经成功地上传了第一个项目~\(≧▽≦)/~啦啦啦~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值