作者:北京雅舍 | 来源:互联网 | 2023-09-24 12:01
前言:
Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。和SVN一样,Git是用于一个开发团队共同管理开发一份代码的版本管理系统,但它相比SVN而言更加强大,因为它具有分布式的特点,而且它在不同的设备上还可以创建一个或多个分支。
1.安装
windows版本git下载:https://git-scm.com/download/win
在安装完成后,在鼠标右键菜单中查看是否有git的菜单项,有的话就说明安装成功了,没有的话可以试试重启下机器。
git gui here 可视化界面操作git
git bash here 使用命令操作git
如果是第一次在机器上使用git,那我们需要先在git的配置文件中写入用户信息(git 的用户名和邮箱 ):
git config --global user.name xxx
git config --global user.email xxxxxxx@xxxx

小贴士:
1、Git中的复制使用的快捷键是:Ctrl+Insert
2、Git中的粘贴使用的快捷键是:Shift+Insert
可通过 git config --list 查看所有git的配置文件

你也可以通过输入 git config
: 来检查 Git 的某一项配置
例如:
git config user.username 查询用户名配置
config 配置有system级别 global(用户级别) 和local(当前仓库)三个
设置先从system-》global-》local 底层配置会覆盖顶层配置 分别使用--system/global/local 可以定位到配置文件
例如:
查看系统配置列表
git config --system --list
查看当前用户配置列表
git config --global --list
查看当前仓库配置列表
git config --local --list
2.创建仓库
在需要管理源代码的文件夹下右键,启动git的命令窗口。
输入git init ,提示成功创建仓库。
这时我们会在当前目录下看到一个.git的隐藏文件。 这样,我们的git仓库算建好了。

3.添加文件到git仓库
输入 git add xxx.xxx 可提交单个文件

git add . 提交当前目录下的所有文件
如果我们需要排除某些文件的添加我们需要创建一个.gitignore文件


这时我们再使用git add . 提交时即可忽略这些文件
注意:使用记事本编辑时需注意文件编码格式,改为utf-8。
关于.gitignore文件的语法,有几点需要说明:
- 如果需要忽略一个文件夹,直接给文件夹名,如:.idea
- 如果需要忽略一个文件夹内的文件,但又不是全部,那就不能直接给文件夹名了,要用“文件夹/*”的形式,否则就算在之前加上“!”也不能提交文件
- 如果需要忽略某一类扩展名的文件可以使用“*.exname”的形式(“.exname”表示开发者指定的扩展名)
- 如果需啊哟忽略某一名称的所有文件可以使用“anyname.*”(“anyname”表示开发指定的文件名)
- .gitignore文件也有类似JS一样的作用域,也就是说不加任何文件夹,而直接在根目录指定忽略文件的名称,那包含在该目录的子目录相同名称文件也会被忽略。如果只想忽略当前目录,而希望影响子目录,那需要在文件前面加上“/”。
4.绑定github
生成sshkey : ssh-keygen -t rsa -C "你的邮箱"

执行 clip <~/.ssh/id_rsa.pub
然后登陆GitHub,选择设置


在C:UsersAdministrator.sshid_rsa.pub 中的ssh key复制到剪贴板,贴到key中,点击add ssh key 就成功啦!!!

5提交代码到github
首先,在github上新建一个仓库


创建完仓库之后将进入仓库,将仓库地址复制来

在命令窗口将仓库克隆下来
git clone "仓库地址"

在下载的目录下添加一个文件并将文件提交至本地仓库
git add test.txt
git commit -m "commit test.txt file"
此时test.txt文件已提交至本地仓库
最后我们将本地仓库的提交同步到github上的远程仓库
git push origin master

中间会弹出一个github的登陆框

登陆后本地仓库就被上传到github的远程仓库上咯。