来自不同用户的 Git pull 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24305178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:13:30  来源:igfitidea点击:

Git pull command from different user

gitgithub

提问by Mohsin Inayat Khan

I am working with my friend on a project the code of which is on Git. If I need to pull the changes from my friend's machine, can I pull it from my username/password using the following command without any issue?

我正在和我的朋友一起开发一个项目,该项目的代码在 Git 上。如果我需要从我朋友的机器上提取更改,我可以使用以下命令从我的用户名/密码中提取它而没有任何问题吗?

git pull https://[email protected]/abc/theproject.git

回答by Davlet D

This command will help to pull from the repository as the different user:

此命令将有助于以不同的用户身份从存储库中提取:

git pull https://[email protected]/projectfolder/projectname.git master

It is a workaround, when you are using same machine that someone else used before you, and had saved credentials

这是一种解决方法,当您使用与您之前其他人使用的同一台机器并且保存了凭据时

回答by gunj_desai

Was looking for the solution of a similar problem. Thanks to the answer provided by Davlet and Cupcake I was able to solve my problem.

正在寻找类似问题的解决方案。感谢 Davlet 和 Cupcake 提供的答案,我能够解决我的问题。

Posting this answer here since I think this is the intended question

在这里发布这个答案,因为我认为这是预期的问题

So I guess generally the problem that people like me face is what to do when a repo is cloned by another user on a server and that user is no longer associated with the repo.

所以我想通常像我这样的人面临的问题是当服务器上的另一个用户克隆一个 repo 并且该用户不再与 repo 相关联时该怎么办。

How to pull from the repo without using the credentials of the old user ?

如何在不使用旧用户凭据的情况下从 repo 中提取?

You edit the .git/config file of your repo.

您编辑存储库的 .git/config 文件。

and change

和改变

url = https://<old-username>@github.com/abc/repo.git/

to

url = https://<new-username>@github.com/abc/repo.git/

After saving the changes, from now onwards git pull will pull data while using credentials of the new user.

保存更改后,从现在开始 git pull 将使用新用户的凭据提取数据。

I hope this helps anyone with a similar problem

我希望这可以帮助任何有类似问题的人

回答by gunj_desai

Your question is a little unclear, but if what you're doing is trying to get your friend's latest changes, then typically what your friend needs to do is to push those changes up to a remote repo (like one hosted on GitHub), and then you fetch or pull those changes from the remote:

您的问题有点不清楚,但是如果您正在做的是尝试获取您朋友的最新更改,那么通常您的朋友需要做的是将这些更改推送到远程存储库(例如托管在 GitHub 上的存储库),并且然后你从远程获取或拉取这些更改:

  1. Your friend pushes his changes to GitHub:

    git push origin <branch>
    
  2. Clone the remote repository if you haven't already:

    git clone https://[email protected]/abc/theproject.git
    
  3. Fetch or pull your friend's changes (unnecessary if you just cloned in step #2 above):

    git fetch origin
    git merge origin/<branch>
    

    Note that git pullis the same as doing the two steps above:

    git pull origin <branch>
    
  1. 您的朋友将他的更改推送到 GitHub:

    git push origin <branch>
    
  2. 如果您还没有克隆远程存储库:

    git clone https://[email protected]/abc/theproject.git
    
  3. 获取或拉取您朋友的更改(如果您只是在上面的第 2 步中进行了克隆,则不需要):

    git fetch origin
    git merge origin/<branch>
    

    请注意,git pull这与执行上述两个步骤相同:

    git pull origin <branch>
    

See Also

也可以看看