ubuntu下配置git,上传代码

1.安装配置git

sudo apt-get install openssh-server openssh-client
sudo apt-get install git

2.用git上传

cd /to/local/path/
git init
git add ./
git commit -m "add your description"

3.添加ssh key

ssh-keygen -t rsa -C "youremail@example.com"

你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可,由于这个Key也不是用于军事目的,所以也无需设置密码。如果一切顺利的话,可以在用户主目录里找到.ssh目录($cat ~/.ssh/id_rsa.pub),里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。

将id_rsa.pub的内容加到github上(打开“Account settings”,“SSH Keys”页面,点“Add SSH Key”)

测试SSH密钥是否配置好。

ssh -T git@github.com

出现问题 Permission denied (publickey)

eval "$(ssh-agent -s)"

4.上传

git remote add origin git@github.com:(path/on/github).git
git push origin master

若提示push的话

git pull origin master

依然报错

git reset --hard FRTCH_HEAD

5.有时候需要change remote origin

git remote rm origin
git remote add origin git@github.com:(path/on/github).git
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Ubuntu上的代码通过Git上传到华为云,您需要进行以下步骤: 1. 在华为云上创建一个Git仓库,获取Git仓库的URL。 2. 在Ubuntu上安装Git,并配置Git用户名和邮箱。 ``` sudo apt-get update sudo apt-get install git git config --global user.name "Your Name" git config --global user.email "youremail@domain.com" ``` 3. 在Ubuntu上使用git clone命令将Git仓库克隆到本地。 ``` git clone git@github.com:username/repo.git ``` 其中,username是您的GitHub用户名,repo是您要克隆的仓库名称。请将其替换为您要克隆的GitHub仓库的URL。 4. 将您的代码复制到克隆的Git仓库中。 ``` cp /path/to/your/code/* /path/to/your/git/repo/ ``` 5. 在Git仓库中添加、提交和推送更改。 ``` git add . git commit -m "add your commit message here" git push origin master ``` 其中,"."表示将所有更改添加到Git仓库中。您可以将其替换为特定的文件或目录。"add your commit message here"是您的提交信息。请将其替换为您自己的提交信息。"origin"是您的Git仓库的别名,"master"是您要推送的分支名称。 6. 输入您的华为云Git仓库的用户名和密码,以完成推送。 ``` Username for 'https://gitee.com': your_username Password for 'https://your_username@gitee.com': your_password ``` 其中,your_username是您的华为云Git仓库的用户名,your_password是您的华为云Git仓库的密码。 7. 检查您的代码是否已成功推送到华为云Git仓库中。 ``` git log git remote -v ``` git log命令将显示您的提交历史记录,git remote -v命令将显示您的Git远程仓库的详细信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值