我怎样才能使用一个命令`git push '到Ubuntu上的GitHub,而不用每次都输入我的电子邮件?

izj3ouym  于 2022-11-20  发布在  Git
关注(0)|答案(2)|浏览(96)

我想在Ubuntu上通过一个命令git push,例如:

echo -e "email\ntoken" | git push origin branchName

git push origin branchName && email && token

但在下完命令后我得在我的邮箱里放上:

fwzugrvs

fwzugrvs1#

如何使用ssh键轻松推送到GitHub/从GitHub拉取

您需要:
1.将您的远程配置为使用GitHub存储库地址的ssh版本,而不是http版本。
1.生成一个公共/私有ssh密钥对,并通过浏览器手动将公共密钥添加到您的GitHub帐户。

详细信息

1.将您的远程配置为使用GitHub存储库地址的ssh版本,而不是http版本。例如:对于我的这个回购:https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world,请使用此ssh URL:git@github.com:电子RCAircraftGuy/eRCaGuy_hello_world.git,而不是下面的HTTPS:https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world.git

# View your current remote servers and their URLs
git remote -v

# Set your `origin` remote server to use the ssh URL instead
# of the HTTPS one
git remote set-url origin https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world.git

1.生成一个公共/私有ssh密钥对,然后通过浏览器手动将公钥添加到你的GitHub账户中。https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh

# generate a public/private ssh key pair
ssh-keygen -t ed25519 -C "your_email@example.com"

# Ensure the ssh-agent is running (this starts the `ssh-agent`)
eval "$(ssh-agent -s)"

# Add your private key to it; update the path to your private key below, as
# required, based on what path you interactively selected above when
# generating the key
ssh-add ~/.ssh/id_ed25519

# Verify what keys have been added to the ssh-agent by listing
# (`-l`) currently-added keys. 
# A. If you see "Could not open a connection to your authentication agent.",
# it means the `ssh-agent` has not been started yet, so you must start it
# with `eval "$(ssh-agent -s)"`. 
# B. If you see "The agent has no identities.", it means the ssh-agent is
# running but you haven't added any ssh keys to it, so run `ssh-add
# path/to/private_key` to add a key to the agent.
ssh-add -l

现在在网页浏览器中登录github,点击您的个人资料图片--〉设置--〉SSH和GPG密钥(左侧)--〉新建SSH密钥--〉复制并粘贴您的.pub密钥文件的内容(例如:在你的Ubuntu机器上运行cat ~/.ssh/id_ed25519.pub来读取公钥--如果你使用了不同的文件名,可以根据需要调整路径)到GitHub这里--〉点击“添加SSH密钥”。
现在,每当你输入git push,它就会自动工作,使用ssh键。

参考

1.我的完整ssh注解:https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh

5lhxktic

5lhxktic2#

您可以将用户名作为https git远程地址的一部分提供一次。
首先运行git remote -vv以获取完整的当前远程URL。
然后,要更改现有遥控器,您可以执行如下命令:

git remote set-url origin https://yourname@github.com/yourname/yourrepo.git

其中新的部分是yourname@(替换您的github用户名),URL的其余部分应该与git remote -vv中所示的相同

相关问题