Github 上传项目(个人令牌token)

1.点击 github头像       :

setting         ->    

Developer Settings        ->      

Personal access  tokens 

2.在要上传的文件夹下运行以下命令:

git init
git commit -m "first commit"
git branch -M main

 利用以下命令模板(根据自己的信息填写):

git remote set-url origin https://<token>@github.com/<username>/<repo>

模板分析(需要修改的部分):

<token>        :刚才生成的个人令牌
<username>:你的github名字
<repo>        : 存储库的名字

再运行:

git push origin main

成功: 

git add .
git commit -m "文案生成app,0.3版本发布"
git branch -M main
git remote set-url origin https://github_pat_11HnpUp2xXdAq6g03WgzkMPqY5628i8ETB4BMC4WQ@github.com/****/Web-Learning
git push origin main

报错(1):

remote: Permission to samrao2/manager-4.git denied to samrao1.
fatal: unable to access 'https://github.com/samrao2/manager-4.git/': The requested URL returned error: 403

解决方式

(1):Token未给出权限,需要勾选权限:

之后使用token再试一次

(2):

  1. 从(Windows)凭据管理器中删除所有GitHub条目

  2. 在Git全局配置中设置useHttpPath = true

git config --global credential.useHttpPath true

您可以通过检查

git config --global -e

若名字错误可以进行修改(自己改):

git config --global user.name "user_name"

更多报错:

(1):To https://github.com/lweac4/Web-Learning ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/lermeqa2wa/Web-Learning' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

当远程仓库包含本地仓库中没有的更改时,您遇到的错误消息是Git中的常见问题。这通常发生在其他人已经推送到远程存储库中的同一个分支,而您的本地分支位于远程分支之后时。以下是你如何解决它:

  1. 从远程存储库拉取最新更改:在推送本地更改之前,您需要集成远程存储库中的更改。使用命令git pull。这将从远程存储库获取更改,并尝试将它们合并到本地分支中。如果没有冲突,它将自动合并更改。

  2. 处理合并冲突:如果您的更改与远程仓库中的更改之间存在冲突,Git会在拉取操作期间通知您。您需要手动解决这些冲突。一旦解决了问题,您将提交更改以完成合并。

  3. Push Your Changes:成功合并后,您现在可以使用git push将本地更改推送到远程存储库。

下面是一个分步指南:

  • 首先,请确保您在正确的分支上使用
  • git status
  • 然后,从远程分支获取并合并更改:
    git pull origin main
  • 如果存在合并冲突,请解决它们。这通常涉及编辑文件以修复冲突,然后添加并提交它们:
    git add . git commit -m "Resolved merge conflicts"
  • 最后,推动你的改变:
    git push origin main

此过程确保您的本地存储库与远程存储库保持最新,然后可以安全地推送更改,而不会导致冲突。

(2):hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name>

您看到的消息是来自Git的提示,关于存储库中初始分支的命名。从历史上看,Git一直使用master作为初始分支的默认名称,但现在已经转向使用更具包容性的术语,社区中的许多人(包括GitHub等平台)已经采用main作为默认分支名称。

以下是这条信息的建议:

  1. 更改未来存储库的默认分支名称:如果要为将来创建的所有新存储库设置不同的默认分支名称,可以使用git config命令。例如,要将main设置为默认分支名称,您可以使用:用途:

    git config --global init.defaultBranch main

    此命令将系统上初始化的所有新存储库的默认分支名称设置为main。这是一个全局的Git配置设置,所以你只需要做一次。

  2. 删除当前分支:如果你刚刚初始化了一个新的仓库,并且它有默认的master分支,但是你想重命名它,你可以使用git branch -m命令。例如,要将分支重命名为main,您可以使用:用途:

    git branch -m main

    此命令将当前分支重命名为main

请记住,如果您正在设置新的存储库,或者如果您在一个分支命名约定非常重要的环境中工作,这些步骤特别有用。对于现有的存储库,特别是与其他人共享的存储库,重命名分支时应谨慎,因为它可能会影响工作流和持续集成/部署配置。

(3):git remote set-url origin https://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Q@github.com/lmawjiq24/Web-Learning error: No such remote 'origin'

错误消息“No such remote 'origin'”表示Git在当前项目中找不到名为'origin'的远程仓库。

这通常发生在远程尚未设置时,或者您在Git存储库中使用不同名称的远程。以下是解决此问题的方法:

  1. 检查现有的远程:首先,检查是否有任何远程设置为您的存储库和他们的名字。您可以使用以下命令执行此操作:

    git remote -v

    此命令将列出与您的存储库沿着的所有远程设备及其URL。

  2. 添加一个新的远程:如果没有名为'origin'的远程,您需要添加它。使用命令:

    git remote add origin [your-repository-url]

    [your-repository-url]替换为仓库的URL。

  3. 设置现有遥控器的URL:如果存在具有不同名称的遥控器,并且您希望将其URL更改为您提供的URL,请使用用途:

    git remote set-url [remote-name] [new-url]

    [remote-name]替换为遥控器的实际名称(例如,upstreamorigin)和[new-url]与新的URL。

  4. 删除现有遥控器:如果您想将现有遥控器重命名为“origin”,您可以使用:用途:

    git remote rename [old-remote-name] origin

    [old-remote-name]替换为遥控器的当前名称。

  5. 设置'origin'的URL:一旦你有一个名为'origin'的远程,你可以设置它的URL,就像你最初尝试的那样:

    git remote set-url origin [your-new-url]

    [your-new-url]替换为您实际的存储库URL。

请记住,在Git中处理remote时,确保remote的名称和URL配置正确,以避免获取、推送和拉取更改时出现问题,这一点很重要。

(4) :To https://github.com/user/Web-Learning
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/user/Web-Learning'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

To https://github.com/user/Web-Learning
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/user/Web-Learning'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

此错误消息表示对Git仓库的推送操作被拒绝,因为远程仓库中存在本地仓库中没有的提交。这是使用Git时常见的情况,尤其是在协作环境中。以下是你如何解决它:

  1. 获取并合并远程更改:您需要首先将本地存储库与远程存储库同步。最简单的方法是将远程更改拉入本地分支。使用以下命令:

    git pull origin main

    此命令从main远程的origin分支获取更改,并将它们合并到本地main分支中。

  2. 解决合并冲突:如果有任何合并冲突,Git会在拉取操作中提醒你。当远程仓库中的更改与本地仓库中的更改重叠时,就会发生这些冲突,而Git无法自动解决这些冲突。您需要手动解决这些冲突。解决后,添加并提交更改。

  3. 推动您的更改:成功集成远程更改(并解决任何冲突)后,您现在可以将本地更改推送到远程存储库:

    git push origin main

如果您想在合并之前查看更改,您可以使用git fetch,然后使用git mergegit rebase,这取决于您对集成更改的偏好。

请记住,经常从远程存储库拉取更改以保持最新并减少推送更改时发生冲突的可能性是一个很好的做法。

(5):From https://github.com/l0aeq4/Web-Learning * branch main -> FETCH_HEAD hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches.

您看到的消息表明您的本地分支和远程分支已经分离,这意味着两者都有另一个没有的更改。Git不确定如何协调这些更改,并要求您指定一个策略来集成这些更改。

以下是Git建议的选项:

  1. 合并(默认策略):这将在本地仓库中创建一个合并提交,将来自远程分支的更改与本地更改相结合。

    要使用此策略,请运行:

    git config pull.rebase false
  2. Rebase:这将在远程分支的更改之上重新应用本地更改。这是一种保持一个更清晰、线性的项目历史的方法。

    要使用此策略,请运行:

    git config pull.rebase true
  3. 仅快进:此选项将仅更新您的本地分支,如果它可以通过快进合并完成(即,如果不存在远程分支不具有的本地提交)。

    要使用此策略,请运行:

    git config pull.ff only

设置好首选策略后,您可以再次运行git pull

下面是如何进行:

  1. 选择并设置一个策略:决定你喜欢哪种策略,并使用上面的命令之一进行设置。如果你不确定,默认的合并策略通常是一个安全的选择。

  2. Pull Changes:设置策略后,从远程拉取更改:

    git pull origin main
  3. 解决任何冲突:如果有冲突,解决它们。然后提交已解决的更改。

  4. Push Your Changes:一旦所有内容都合并并解决了所有冲突,您就可以将更改推送到远程存储库:

    git push origin main

(6):From https://github.com/lsuea4/Web-Learning
 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories


出现错误消息“致命:拒绝合并无关的历史”时,

--allow-unrelated-histories 标志与 git pullgit merge 命令这告诉

  1. 使用允许不相关历史的拉取:运行以下命令拉取远程分支并将其与本地分支合并,允许不相关的历史:

  2. git pull origin main --allow-unrelated-histories
  3. 解决任何合并冲突:在拉取操作之后,如果有任何合并冲突,Git会通知你。您需要手动解决这些冲突。一旦解决了所有冲突,就可以暂存更改并提交它们。

  4. 提交合并:解决冲突(如果有)后,提交更改以完成合并:

    git commit -m "Merged unrelated histories"
  5. Push Your Changes:提交合并后,您可以将更改推回远程存储库:

    git push origin main

请注意,合并不相关的历史应谨慎行事,因为它可能会导致复杂的合并冲突。如果这两个仓库/分支有很大且不同的历史,这一点尤其正确。这也是一个很好的实践,确保您首先理解为什么历史记录是不相关的,以避免项目开发过程中的潜在问题。

 (7):On branch main
nothing to commit, working tree clean

很好,消息“On分支main,nothing to commit,working tree clean”表明您的本地工作目录是干净的,这意味着在您当前的分支(`main`)中没有未提交的更改。这是一个很好的状态,特别是在解决了Git问题之后,因为这意味着你的本地仓库与你的最后一次提交是同步的。 下面是你可以做的:

1. ** 检查状态 **:最好仔细检查仓库的状态。您可以用途:

git status

这将确认所有内容都是最新的,并且没有未跟踪的文件或要提交的更改。

2. **Pull Latest Changes**:如果还没有,请确保本地分支与远程仓库保持最新: "

git pull main

这将使用远程“main "分支的最新更改更新本地”main"分支。

3. **Push Your Changes**:如果您在本地提交了任何尚未推送到远程仓库的提交,那么现在是一个很好的时机:

git push origin main

因为你的工作树是干净的,这个命令只会将新的提交(如果有的话)推送到远程。

4. ** 继续工作 **:如果您有更多的更改,您可以继续处理代码。在进行更改之后,不要忘记添加、提交并最终推送这些更改,以保持远程存储库的更新。

5. ** 分支 **:如果您计划启动新功能或修复,通常创建一个新分支是一个很好的做法: "

git checkout -B [new-branch-name]

将`[new-branch-name]`替换为与您将在此分支上执行的工作相关的名称。 请记住,定期从远程存储库中拉取和推送到远程存储库有助于保持您的工作与团队同步,并减少复杂合并冲突的可能性。

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值