Visual Studio 代码推送到 Gitee 完整指南
前提准备
1. 确保已安装必要工具
- Visual Studio 2019/2022(包含 Git 工具)
- Git for Windows(如果 VS 没有内置)
- Gitee 账号
2. 检查 Git 配置
打开 Visual Studio 的开发者命令提示符或Git Bash,配置用户信息:
在 Visual Studio 中将代码推送到 Gitee 的完整流程。首先需安装 Visual Studio 及 Git 工具并配置用户信息。接着在 Gitee 创建远程仓库,在 VS 中初始化本地 Git 仓库并添加远程地址。通过 Git 更改窗口暂存并提交代码,最后推送到远程。文中提供了图形界面和命令行两种方法,包含.gitignore 推荐配置及常见问题解决方案,如身份验证、大文件处理及中文乱码修复。遵循频繁提交、清晰信息及分支管理等最佳实践可提升开发效率。
打开 Visual Studio 的开发者命令提示符或Git Bash,配置用户信息:
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱@example.com"
WinformDetect(或你的项目名)https://gitee.com/你的用户名/WinformDetect.gitoriginhttps://gitee.com/你的用户名/WinformDetect.githttps://gitee.com/你的用户名/WinformDetect.gitInitial commit: 针孔缺陷检测系统origin 作为远程仓库在项目根目录打开Git Bash或开发者命令提示符
# 1. 初始化 Git 仓库
git init
# 2. 添加远程仓库
git remote add origin https://gitee.com/你的用户名/WinformDetect.git
# 3. 创建.gitignore 文件(可选,推荐)
echo "bin/" >> .gitignore
echo "obj/" >> .gitignore
echo "*.user" >> .gitignore
echo "*.suo" >> .gitignore
echo ".vs/" >> .gitignore
# 4. 添加所有文件到暂存区
git add .
# 5. 提交更改
git commit -m "Initial commit: 针孔缺陷检测系统"
# 6. 推送到远程仓库
git push -u origin master
为 Visual Studio 项目创建合适的.gitignore文件:
## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons.
# User-specific files
*.rsuser *.suo *.user *.userosscache *.sln.docstates
# Build results
[Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# 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
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core project.lock.json
project.fragment.lock.json artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c *_p.c *_h.h *.ilk *.meta *.obj *.iobj *.pch *.pdb *.ipdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *_wpftmp.csproj *.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
# Visual Studio Trace Files
*.e2e
# 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
# AxoCover is a Code Coverage Tool
.axoCover/* !.axoCover/settings.json
# Visual Studio code coverage results
*.coverage *.coveragexml
# 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
# Note: 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 files may be visible to others.
*.azurePubxml
# 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 *.appx *.appxbundle *.appxupload
# 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 orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# 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 ;-)
_UgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm CDF_UpgradeReport.xml
# SQL Server files
*.mdf *.ldf *.ndf
# Business Intelligence projects
*.rdl.data *.bim.layout *.bim_*.settings *.rptproj.rsuser *- [Bb]ackup.rdl *- [Bb]ackup ([0-9]).rdl *- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# 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/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/ *.pyc
# Cake - Uncomment if you are using it
# tools/** # !tools/packages.config
# Tabs Studio
.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs *.btm.cs *.odx.cs *.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Output folders for your project
output/ img/
问题:推送时要求用户名密码 解决方案:
问题:某些文件超过 Gitee 限制 解决方案:
# 检查大文件
git ls-files | xargs ls -l | sort -k5 -rn | head
# 移除大文件并添加到.gitignore
git rm --cached 大文件名
echo "大文件名" >> .gitignore
问题:中文文件名显示乱码 解决方案:
git config --global core.quotepath false
问题:push rejected 解决方案:
# 先拉取远程更改
git pull origin master --allow-unrelated-histories
# 再推送
git push origin master
git add .
git commit -m "描述你的更改"
git push origin master
# 创建新功能分支
git checkout -b feature/新功能名称
# 完成开发后合并到主分支
git checkout master
git merge feature/新功能名称
git push origin master
通过以上步骤,就可以成功将 Visual Studio 项目推送到 Gitee,并建立完整的版本控制工作流程。

微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online
将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online