ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

初始git push代码及后续管理

初始git push代码及后续管理 使用浏览器可以访问github并创建新的远程仓库但通过VScode中git插件的代码提交常常因网络问题而失败。这里介绍github官网推荐的通过ssh连接后通过git命令行提交。前提1. 可以登录github以创建新远程仓库2. 已在github上配置好本地ssh密钥对。1、在github上创建新的远程仓库例如我这里创建名为“Fiji-auto-measure”的新仓库关于Fiji/image J自动处理荧光图片。2、在本地PowerShell上进行本地仓库初始化、关联和提交定位到本地文件夹将其初始化为本地仓库cd /path/to/your/project git init添加文件到本地仓库# 添加指定文件 git add 文件名 # 添加文件夹内全部文件 git add .还可以选择性忽略部分文件将其放入.gitignore# 创建.gitignore New-Item .gitignore -ItemType File # VScode中打开 code .gitignore写入*.png # 忽略所有 PNG 文件 *.csv # 忽略所有 CSV 文件 images/ # 忽略整个 images 文件夹提交.gitignoregit add .gitignore关联远程仓库github中和本地仓库本地.gitgit remote add origin gitgithub.com:username/repo_name.git其中gitgithub...即ssh连接地址在创建仓库时github会自动给出origin就是gitgithub...的简称可以随便取一般都取为origin。提交本地仓库到远程仓库。注意1、首次提交必须先创建分支main or mastergit branch -M main # make sure branch is main (or master)2、git push之前一定要先git commit -m 写点描述# 添加描述信息 git commit -m Initial commit # 提交到关联远程仓库origin的指定分支main git push -u origin main # 首次提交需用“-u”关联仓库-分支3、后续提交新版本代码git status # 查看修改变化与最近历史版本的区别 git add filename # for specific files git add . # for all changes git commit -m Describe what you changed # 一定要有 git push # 默认提交到origin-main使用“-u”可关联新分支
返回列表