Git&GitHub学习和运用(3.GitHub实战运用)

 配置全局忽略文件.gitignore

  例举dotNet开发的一个场景来讲明“忽略文件”的做用,在开发过程当中每每在编辑代码后,VS在每次编译后会生成一些项目构建文件例如bin目录、obj目录等。然而这些文件并不须要进行版本控制,由于每一个人每次编译后都会自动生成,若是频繁上传至Git那么会形成空间的占用,其余人检出文件时增长下载的时间。因此在第一次将项目使用Git版本控制时,就须要建立该文件,来避免相似的问题。html

  基于以上的场景,说到底就是咱们不但愿项目中的文件进行版本控制(忽略掉),那么此时就能够配置一个全局的忽略文件.gitignore。node

  建立全局的忽略文件.gitignore步骤以下:git

   1.选择一个目录(推荐Git安装目录),在该目录打开Git命令行工具,输入命令(建立忽略文件):github

touch .gitignore_global

 

   2. 将该文件配置为全局的忽略文件,输入命令:web

git config --global core.excludesfile ~/.gitignore_global

  

  3.打开.gitignore_global文件添加忽略规则,在这里不详细介绍规则的编写,由于这些东西每每都是通用化的都用现有的模板拿来用,若是不是专门的版本控制系统管理员,那就没必要浪费时间研究。以下附上一个模板,能够根据模板内容自行扩展:json

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

 

  4.另外须要强调的一点:若是你的项目已经创建Git版本库,那这个时候在添加.gitignore文件后是没有效果的,须要咱们手动删除缓存,命令以下:缓存

git rm -r --cached .

7.GitHub的使用

  GitHub是基于Git版本控制系统并将项目工程架设到云端进行托管的平台。下面以项目经理和开发人员创建新项目的维度来介绍GitHub的使用流程。sass

  注:若是是进行演练操做,请自行准备好两个GitHub帐号分别对应项目经理和开发人员。app

7.1.在本地使用Git搭建一个代码仓库(项目经理)

在项目根目录打开Git命令行工具,输入:ide

git init

操做参考图:

   

7.2.为代码仓库配置本身的用户信息,其中包括用户名和邮箱(项目经理)

操做参考图:

 

7.3.添加并提交项目代码(项目经理)

 操做命令:

git add *
git commit -m "注释"

 

7.4.GitHub准备工做(项目经理)

7.4.1.提早注册号帐号并登录GitHub

7.4.2.在GitHub上建立项目

  操做参考图1:

 

   操做参考图2:

 

   操做参考图3:

 至此建立完成。

 

7.5.Git配置和操做(项目经理)

7.5.1.配置远程地址

操做命令:

git remote add <远端代号> <远端地址>

<远端代号> :链接代号。通常直接使用origin做代号,也能够自定义。至关于存储远端地址的变量名称。

<远端地址> :GitHub项目的Url。

 操做参考图:

 注:以上配置的信息能够在隐藏目录.git下的config文件中查看。

 

7.5.2.将项目仓库推送到GitHub

操做命令:

git push <远端代号> <本地分支名称>

输入命令后会提示输入GitHub的用户名和密码

操做参考图:

 至此推送完毕。

在GitHub查看推送的结果:

 

7.6.从GitHub中将项目以HTTP方式克隆到本地(开发人员)

7.6.1.选取一个项目存放目录在该目录下打开Git命令行

输入操做命令:

git clone <GitHub远程URL>

操做参考图:

 

7.6.2.为项目配置用户信息

操做参考图:

 

7.7.项目功能开发完成后进行新增和提交操做

操做参考图:

 

7.8.在GitHub上设置项目合做人员(项目经理&开发人员)

7.7.1.要确保进行推送(push)操做的帐号具备权限(为GitHub项目邀请合做人员)

 点击绿色按钮进行邀请,邀请后复制用于邀请对方的URL:

 7.7.2.项目经理发送邀请后,开发人员须要将邀请的URL进行访问,在页面中接受邀请。

操做参考图:

 

7.8.推送(开发人员)

操做命令:

git push origin master

操做参考图:

 PS:输入push命令后会要求填写用户名和密码。

 

7.9.获取(pull)开发人员在GitHub上推送(push)的内容(项目经理)

操做命令:

git pull origin master

操做参考图:

相关文章
相关标签/搜索