1.下载,安装
一般情况下ubuntu配置了git,如果没有话通过如下命令进行下载
sudo apt-get install git-all
2.创建本地的git仓库
git config --global user.name "xxx"
git config --global user.email "xxx@email.com"
git init
git add .
git commit -m first
3.获取token等信息
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
<your_token>:换成你自己得到的token
<USERNAME>:是你自己github的用户名
<REPO>:是你的仓库名称
例如git remote set-url origin https://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@github.com/shliang0603/
4.将本地的push到github仓库
git push -u origin master
或者 git push -u origin master:main。这时就可以把本地的master分支push到远程的main分支
可能问题1
$ git push origin master
To http://xxxxxx/test.git
! [rejected] master -> master(fetch first)
error: failed to push some refs to 'http://xxxxxx/Android.git'
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.
github上代码有些没有同步到本地,先同步再push
git pull origin
git push origin master
可能问题2
remote: Support for password authentication was removed on August 13, 2021. Please use a person
由于密码登入被弃用,所以应该采用步骤3中所提到的过程用token进行登入。