{"id":20231004,"url":"https://github.com/bewaremypower/learninggit","last_synced_at":"2026-03-09T04:06:21.609Z","repository":{"id":109020357,"uuid":"114542551","full_name":"BewareMyPower/learninggit","owner":"BewareMyPower","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-09T10:10:27.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T00:22:33.230Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BewareMyPower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-17T14:24:03.000Z","updated_at":"2019-09-09T10:10:29.000Z","dependencies_parsed_at":"2023-08-26T16:15:10.176Z","dependency_job_id":null,"html_url":"https://github.com/BewareMyPower/learninggit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Flearninggit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Flearninggit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Flearninggit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Flearninggit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BewareMyPower","download_url":"https://codeload.github.com/BewareMyPower/learninggit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241677354,"owners_count":20001673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T07:44:48.936Z","updated_at":"2026-03-09T04:06:15.094Z","avatar_url":"https://github.com/BewareMyPower.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 测试本地git添加远程库到github\nLinux下把上传命令的origin改成o才行，否则会出现奇怪的不能上传的错误\n```\ngit remote add o git@github.com:BewareMyPower/learninggit.git\ngit push -u o master\n```\n\n找到了原因, 打开.git/config文件，可以看到\n\u003e [branch \"master\"]  \n\u003e \tremote = o  \n\u003e \tmerge = refs/heads/master  \n\ngit init默认生成的配置文件中，master分支的remote属性是o而非origin\n\n修改README.md后重新上传文件出现问题，解决方式是添加强制上传选项\n`git push o master -f`\n\n# 测试github多账号切换\n```\nssh-keygen -t rsa -f ~/.ssh/id_rsa_\u003cname\u003e -c \u003cyour-email\u003e\n```\n\n根据自定义的`name`得到公钥`id_rsa_\u003cname\u003e.pub`和私钥`id_rsa_\u003cname\u003e`，把公钥的部分添加到对应仓库的SSH keys中。\n\n最关键的就是编辑`~/.ssh/config`文件，对每个账号，添加如下代码：\n```\nHost \u003cyour-host\u003e\n    HostName \u003cyour-host-name\u003e\n    User git\n    IdentityFile ~/.ssh/id_rsa_\u003cname\u003e\n```\n\n这里`your-host`和`your-host-name`都填的仓库地址（即git@后面的那一串），比如github就填`github.com`。\n\n然后对于每个项目，设置单独的用户名和密码，需要进入git项目目录：\n```\ngit config user.name \u003cyour-user-name\u003e\ngit config user.email \u003cyour-user-email\u003e\n```\n\n可以发现在`.git/config`文件中加上了：\n```\n[user]\n\tname = \u003cyour-user-name\u003e\n\temail = \u003cyour-user-email\u003e\n```\n\n因此直接修改该文件也行。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewaremypower%2Flearninggit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbewaremypower%2Flearninggit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewaremypower%2Flearninggit/lists"}