git 项目的更新

news2025/2/6 17:44:11

更新项目

当自己的本地项目与 远程的github 的仓库已经建立远程连接时, 则直接按照下面的步骤,

将本地的项目代码更新到远程仓库。


# Stage the resolved file
git add README.md <file1> <file2>

# To stage all changes:
git add .

# Commit the merge
git commit -m "Resolved merge conflict in README.md"

# Push the changes
git push origin main

如果在此之前, 自己的本地仓库并没有与远程的仓库建立连接时, 则先需要按照下面的步骤进行连接建立。

1. 建立连接

由于github在 2021 年开始, 取消使用密码登录的方式, 因此 这里推荐使用第二种 通过ssh 连接的方式,进行登录。

The error occurs because GitHub no longer supports password-based authentication for HTTPS URLs (as of August 13, 2021). Instead, you need to use one of the following authentication methods:


Option 1: Use a Personal Access Token (PAT)

GitHub now requires a Personal Access Token (PAT) instead of a password for HTTPS authentication.

Steps:
  1. Generate a PAT:

    • Go to your GitHub account settings: GitHub Tokens.
    • Click Generate new token.
    • Select the appropriate scopes (e.g., repo for full control of private repositories).
    • Generate the token and copy it (you won’t be able to see it again).
  2. Use the PAT for Authentication:

    • When prompted for a password, paste the PAT instead of your GitHub password.

    Example:

    Username for 'https://github.com': your_account
    Password for 'https://xxxxx@github.com': <paste-your-PAT-here>
    

Option 2: Use SSH Authentication

SSH is a more secure and convenient way to authenticate with GitHub.

Steps:
  1. Generate an SSH Key (if you don’t already have one):
    • Run the following command in your terminal:
      ssh-keygen -t ed25519 -C "your_email@example.com"
      
    • Press Enter to accept the default file location and passphrase (optional).

The command ssh-keygen -t ed25519 -C "your_email@example.com" is used to generate a new SSH key pair for secure authentication with remote servers, such as GitHub. Let’s break down the command and its components:


Command Breakdown

  1. ssh-keygen:

    • This is the command-line tool used to generate, manage, and convert SSH keys.
  2. -t ed25519:

    • The -t flag specifies the type of key to generate.
    • ed25519 is a cryptographic algorithm used to create the key pair. It is a modern, secure, and efficient algorithm based on elliptic curve cryptography.
    • You can replace ed25519 with other algorithms, such as:
      • rsa: Older but widely supported algorithm (e.g., -t rsa -b 4096 generates a 4096-bit RSA key).
      • ecdsa: Elliptic Curve Digital Signature Algorithm (e.g., -t ecdsa -b 521 generates a 521-bit ECDSA key).
      • dsa: Older and less secure (not recommended).
  3. -C "your_email@example.com":

    • The -C flag adds a comment to the key, which is typically your email address or a label to help identify the key.
    • This comment is embedded in the public key file and is useful for keeping track of which key is associated with which account or purpose.

Why Use Different Algorithms (-t Options)?

You can use different algorithms (ed25519, rsa, ecdsa, etc.) for different repositories or purposes, but this is not common practice. Instead, people usually generate one key per machine or purpose and reuse it across multiple repositories. However, here are some reasons you might use different algorithms:

  1. Compatibility:

    • Some older systems or services may not support modern algorithms like ed25519. In such cases, you might need to use rsa or ecdsa.
  2. Security Requirements:

    • If you have specific security requirements, you might choose an algorithm based on its strength or performance characteristics.
  3. Organizational Policies:

    • Some organizations enforce specific key types for compliance or standardization.

How to Use Different Keys for Different Repositories

If you want to use different SSH keys for different repositories, you don’t need to generate keys with different algorithms. Instead, you can:

  1. Generate multiple SSH key pairs (e.g., one for work and one for personal use).
  2. Add the keys to your SSH agent.
  3. Configure your SSH client to use the appropriate key for each repository using the ~/.ssh/config file.

Summary

  • The command ssh-keygen -t ed25519 -C "your_email@example.com" generates a secure SSH key pair using the ed25519 algorithm.
  • You can use different algorithms (-t options) for compatibility or specific requirements, but it’s not necessary for managing multiple repositories.
  • To use different keys for different repositories, generate multiple keys and configure them in your ~/.ssh/config file.

Let me know if you need further clarification!

  1. Add the SSH Key to Your GitHub Account:

    • Copy the public key to your clipboard:
      cat ~/.ssh/id_ed25519.pub
      
    • Go to your GitHub account settings: GitHub SSH Keys.
    • Click New SSH key, give it a title, and paste the public key.
  2. Change the Remote URL to SSH:

这里注意 使用的 git@github.com

  • Update your remote repository URL to use SSH instead of HTTPS:
    git remote set-url origin git@github.com:xxxx_name/respitory.git
    
    
    

这里需要注意, 你远程的仓库 使用的是main 还是 master.

  • Now you can push without entering a username or password:
    git push origin main
    

Option 3: Use GitHub CLI

If you have the GitHub CLI installed, you can authenticate using the gh command.

Steps:
  1. Install the GitHub CLI: GitHub CLI Installation.
  2. Authenticate with GitHub:
    gh auth login
    
  3. Follow the prompts to log in and authorize the CLI.

Option 4: Use a Credential Helper

You can configure Git to remember your credentials.

Steps:
  1. Enable the credential helper:
    git config --global credential.helper store
    
  2. Push your changes. The first time, you’ll be prompted for your username and PAT. After that, Git will remember your credentials.

Summary

  • Recommended: Use a Personal Access Token (PAT) or switch to SSH for authentication.
  • If you’re unsure, start with the PAT method.

2. 处理冲突

当远程仓库和本地仓库发生冲突时, 需要先解决冲突

我们正常更新时的状态是, 远程仓库的文件在本地是具有的,
而如果远程的文件在本地中不存在时, push 时就会存在冲突, 此时需要先需要拉取远程中的文件,然后,根据自己的选择,进行更新或者更改, 之后在推送。

The error indicates that the remote repository has changes that you don’t have locally, and Git is preventing you from overwriting those changes. To resolve this, you need to pull the remote changes first, merge them with your local changes, and then push your updates.


Steps to Fix the Issue:

  1. Pull the Remote Changes:
    Run the following command to fetch and merge the remote changes into your local branch:

    git pull origin main
    
    • If you’re using SSH, it will look like this:
      git pull origin main
      
    • If you’re using HTTPS, it will prompt you for your GitHub username and Personal Access Token (PAT).
  2. Resolve Conflicts (if any):

    • If there are merge conflicts, Git will notify you. Open the conflicting files, resolve the conflicts, and save the changes.
    • After resolving conflicts, stage the resolved files:
      git add <file1> <file2>
      
  3. Commit the Merge:
    If there were conflicts, commit the merge:

    git commit -m "Merge remote changes into local branch"
    
  4. Push Your Changes:
    Once the remote changes are merged with your local changes, push your updates:

    git push origin main
    

Optional: Force Push (Not Recommended)

If you’re sure you want to overwrite the remote changes (e.g., if you’re working alone and don’t care about the remote changes), you can force push:

git push --force origin main

Warning: Force pushing can overwrite remote changes, so use it with caution, especially in collaborative environments.


Summary of Commands:

git pull origin main
# Resolve conflicts if any
git add .
git commit -m "Merge remote changes"
git push origin main

3. 手动解决冲突

The git pull command resulted in a merge conflict in the README.md file. This happens when Git cannot automatically merge changes from the remote repository with your local changes. You’ll need to manually resolve the conflict before proceeding.


Steps to Resolve the Conflict:

  1. Open the Conflicted File:
    Open the README.md file in your text editor or IDE. You’ll see conflict markers like this:
    <<<<<<< HEAD
    Local changes
    =======
    Remote changes
    >>>>>>> 7006db8
    

注意, 等号线上方的代表的本地仓库中的内容, 等号线下面的代表的是远程仓库中的内容,
需要根据自己的需求, 进行更改。

  • <<<<<<< HEAD indicates the start of your local changes.
  • ======= separates your local changes from the remote changes.
  • >>>>>>> 7006db8 indicates the end of the remote changes.
  1. Resolve the Conflict:
    Edit the file to keep the changes you want. For example:

    • Keep both changes:
      Local changes
      Remote changes
      
    • Keep only local changes:
      Local changes
      
    • Keep only remote changes:
      Remote changes
      

    Remove the conflict markers (<<<<<<<, =======, and >>>>>>>) after resolving.

  2. Stage the Resolved File:
    Once you’ve resolved the conflict, stage the file:

    git add README.md
    
  3. Commit the Merge:
    Commit the resolved changes:

    git commit -m "Resolved merge conflict in README.md"
    
  4. Push Your Changes:
    Push the resolved changes to the remote repository:

    git push origin main
    

Example Workflow:

# Open README.md and resolve conflicts
nano README.md

# Stage the resolved file
git add README.md

# Commit the merge
git commit -m "Resolved merge conflict in README.md"

# Push the changes
git push origin main

Additional Notes:

  • If you’re unsure how to resolve the conflict, you can use a merge tool like meld, kdiff3, or the built-in tools in your IDE (e.g., VS Code).
  • To abort the merge and start over (if needed), run:
    git merge --abort
    

小结

全局配置git 上的用户名和email:

       git config --global  user.name "username"
       git config --global  user.email   1234567@email.com

在本地的client 的git, 配置git初始化默认的分支由master 变为main;

git config --global init.defaultBranch main

upload

一 : 上传大量文件(适用于在github上 刚新建一个的仓库A)

1.在本地新建工程文件夹T,将所有待上传的文件拷贝到T中;

2.在T中空白处,点击git bash here; 在github 上点击copy 刚刚仓库A的地址;

3.使用 git clone “仓库A的地址” ,从github 上拉取该仓库到本地;

4.在本地T中, cd到仓库A的路径下,注意到此时在显示 (main),代表进入到该仓库中;

5.在T中将待上传的文件拷贝到 仓库A中, 输入 “git add .” ,注意空格和点号;

6.输入 git commit -m “your logs infor” ;

7.输入 git push -u origin main, 将本地仓库push 到 github 上面,完成代码上传。

note: git add . : 是将当前目录下所有文件添加到 待上传区域;
git add xx.txt : 可以指定当前目录下待上传的文件;

  git push  -u origin main:  -u 代表首次提交, 后续更新提交时,可以不用;

remote

二:本地仓库远程连接到 github 上已经有的仓库。

1.在本地文件夹T中空白处,点击git bash here; 输入git init;

2.将本地的仓库关联到Github上:
git remote add origin https://github.com/h-WAVES/test0913

  1. 选中待上传的文件, 文件之间空格隔开;
    git add file1 fiel2;

  2. 备注此次操作的信息
    git commit -m “logs”

  3. 上传之前先进行Pull 确认一下;如果在github上初始化仓库时,使用第二个;
    git pull origin main
    git pull --rebase origin main

  4. 待上传的文件push 到远程仓库中;
    git push origin main



##  delete
三  删除远程仓库中的文件夹

1.在本地文件夹T中空白处,点击git bash  here; 输入git init;

2.git clone 项目地址, cd  到该对应的路径下    

3.git  rm -r   folder/

4. git commit -m  "delete folder"

5. git push origin main

完成删除


OpenSSL SSL_read: Connection was reset, errno 10054; 解除SSL 验证:

       git config --global http.sslVerify "false"             
当github 创建仓库时,选择了初始化.gitignore 和 README.md 时, 
此时在github 上和本地的仓库由于文件的不同出现不匹配的情况:

对于error: failed to push some refsto‘远程仓库地址’
     
        git pull --rebase origin main

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2293892.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

UE虚幻引擎No Google Play Store Key:No OBB found报错如何处理

UE虚幻引擎No Google Play Store Key&#xff1a;No OBB found报错如何处理&#xff1f; 问题描述&#xff1a; UE成功打包APK并安装过后&#xff0c;启动应用时提示&#xff1a; No Google Play Store KeyNo OBB found and no store key to try to download. Please setone …

吴恩达深度学习——卷积神经网络实例分析

内容来自https://www.bilibili.com/video/BV1FT4y1E74V&#xff0c;仅为本人学习所用。 文章目录 LeNet-5AlexNetVGG-16ResNets残差块 1*1卷积 LeNet-5 输入层&#xff1a;输入为一张尺寸是 32 32 1 32321 32321的图像&#xff0c;其中 32 32 3232 3232是图像的长和宽&…

LabVIEW的智能电源远程监控系统开发

在工业自动化与测试领域&#xff0c;电源设备的精准控制与远程管理是保障系统稳定运行的核心需求。传统电源管理依赖本地手动操作&#xff0c;存在响应滞后、参数调节效率低、无法实时监控等问题。通过集成工业物联网&#xff08;IIoT&#xff09;技术&#xff0c;实现电源设备…

【自动化办公】批量图片PDF自定义指定多个区域识别重命名,批量识别铁路货物运单区域内容改名,基于WPF和飞桨ocr深度学习模型的解决方案

项目背景介绍 铁路货运企业需要对物流单进行长期存档&#xff0c;以便后续查询和审计。不同的物流单可能包含不同的关键信息&#xff0c;通过自定义指定多个区域进行识别重命名&#xff0c;可以使存档的图片文件名具有统一的规范和明确的含义。比如&#xff0c;将包含货物运单…

neo4j-在Linux中安装neo4j

目录 切换jdk 安装neo4j 配置neo4j以便其他电脑可以访问 切换jdk 因为我安装的jdk是1.8版本的&#xff0c;而我安装的neo4j版本为5.15,Neo4j Community 5.15.0 不支持 Java 1.8&#xff0c;它要求 Java 17 或更高版本。 所以我需要升级Java到17 安装 OpenJDK 17 sudo yu…

专业学习|通过案例了解蒙特卡罗模拟实操步骤与含义

一、蒙特卡罗模拟介绍 蒙特卡罗模拟&#xff08;Monte Carlo Simulation&#xff09;是一种基于随机采样的数值计算方法&#xff0c;用于解决具有不确定性或复杂概率分布的问题。其核心思想是通过多次随机抽样来逼近系统的行为或目标函数的真实值&#xff0c;进而对系统进行评估…

数据结构【链栈】

基于 C 实现链表栈&#xff1a;原理、代码与应用 一、引言 栈就是一个容器&#xff0c;可以当场一个盒子&#xff0c;只能一个一个拿&#xff0c;一个一个放&#xff0c;而且是从上面放入。 有序顺序栈操作比较容易【会了链栈之后顺序栈自然明白】&#xff0c;所以我们这里只…

人工智能|本地部署|ollama+chatbox快速Windows10下部署(初级篇)

一、 前言&#xff1a; 其实早一个月我已经使用过deepseek&#xff0c;并且也在自己的机器上通过ollama部署过&#xff0c;但一直没有太多动力&#xff0c;现在感觉还是的记录一下&#xff0c;省的自己给忘掉了 本文只是简单记录一下ollamaopen-webuichatbox部署通过网盘分享…

Android Studio 下载安装教程(2024 更新版),附详细图文

今天&#xff0c;为大家带来的是Android Studio 2024更新版的下载安装教程&#xff0c;包含详细图文步骤。 随着 Android Studio 的不断更新&#xff0c;自从引入 Koala 系列后&#xff0c;其版本号的命名规则也发生了变化。以本次更新为例&#xff0c;版本号为 2024.2.1&#…

6.【BUUCTF】[SUCTF 2019]CheckIn

打开题目页面如下 看样子是一道有关文件上传的题 上传一句话木马 显示&#xff1a;非法后缀&#xff01; 看来.php后缀被过滤了 上传一张带有木马的照片 在文件地址处输入cmd 输入以下代码执行 copy 1.jpg/b4.php/a 5.jpg 最后一行有一句话木马 上传带有木马的图片 但其实…

在线教程丨YOLO系列10年更新11个版本,最新模型在目标检测多项任务中达SOTA

YOLO (You Only Look Once) 是计算机视觉领域中最具影响力的实时目标检测算法之一&#xff0c;以其高精度与高效性深受业界青睐&#xff0c;广泛应用于自动驾驶、安防监控、医疗影像等领域。 该模型最早于 2015 年由华盛顿大学研究生 Joseph Redmon 发布&#xff0c;开创了将目…

FreeRTOS学习 --- 中断管理

什么是中断&#xff1f; 让CPU打断正常运行的程序&#xff0c;转而去处理紧急的事件&#xff08;程序&#xff09;&#xff0c;就叫中断 中断执行机制&#xff0c;可简单概括为三步&#xff1a; 1&#xff0c;中断请求 外设产生中断请求&#xff08;GPIO外部中断、定时器中断…

Docker基础以及单体实战

Docker 一、Docker1.1 Docker组成1.2 Dcoker运行图1.3 名称空间Namepace 1.4 docker、Docker compose、kubermetes 二、Docker安装2.1 在线Docker安装2.2 使用官方通用安装脚本2.3 二进制安装Docker三、Docker基础命令3.1 启动类3.2 镜像类3.3 容器类3.4 网络类3.5 Docker comp…

FFmpeg rtmp推流直播

文章目录 rtmp协议RTMP协议组成RTMP的握手过程RTMP流的创建RTMP消息格式Chunking(Message 分块) rtmp服务器搭建Nginx服务器配置Nginx服务器 librtmp库编译推流 rtmp协议 RTMP&#xff08;Real Time Messaging Protocol&#xff09;是由Adobe公司基于Flash Player播放器对应的…

2025Java面试题超详细整理《微服务篇》

什么是微服务架构&#xff1f; 微服务框架是将某个应用程序开发划分为许多独立小型服务&#xff0c;实现敏捷开发和部署&#xff0c;这些服务一般围绕业务规则进行构建&#xff0c;可以用不同的语言开发&#xff0c;使用不同的数据存储&#xff0c;最终使得每个服务运行在自己…

IIC重难点-2

一、光环境传感器硬件原理图 二、i.MX6ull I2C控制器介绍 1. Inter IC (I2C)提供标准I2C从机和主机的功能。I2C被设计为兼容标准NXP I2C总线协议。 2. I2C是一种双线双向串行总线&#xff0c;它提供了一种简单有效的数据交换方法&#xff0c;最大限度地减少了…

优化数据库结构

MySQL学习大纲 一个好的数据库设计方案对于数据库的性能尝尝会起到事倍功半的效果&#xff0c;合理的数据库结构不仅使数据库占用更小的磁盘空间&#xff0c;而且使查询速度更快。数据库结构的设计需要考虑数据冗余、查询和更新速度、字段的数据类型是否合理等多方面的内容&…

2. K8S集群架构及主机准备

本次集群部署主机分布K8S集群主机配置主机静态IP设置主机名解析ipvs管理工具安装及模块加载主机系统升级主机间免密登录配置主机基础配置完后最好做个快照备份 2台负载均衡器 Haproxy高可用keepalived3台k8s master节点5台工作节点(至少2及以上)本次集群部署主机分布 K8S集群主…

51单片机07 串口通信

串口是一种应用十分广泛的通讯接口&#xff0c;串口成本低、容易使用、通信线路简单&#xff0c;可实现两个设备的互相通信。单片机的串口可以使单片机与单片机、单片机与电脑、单片机与各式各样的模块互相通信。51单片机内部自带UART&#xff08;Universal Asynchronous Recei…

Java进阶——IO 流

文章目录 Java进阶——IO 流 1、File 类的使用 1.1、File 常用构造器1.2、路径分隔符1.3、File 的常用方法 2、IO流原理及流的分类 2.1、IO流原理2.2、流的分类 3、IO流的体系结构4、节点流 4.1、FileReader 读入数据的操作4.2、FileWriter 写出数据的操作4.3、FileReader 和 …