git and github
github 和 git的使用。
注册 github。
安装git。
设置ssh
- 使用ssh 免密登陆github。 如果不用ssh,使用https,那么每次git push git pull,就需要输入github的账号和密码。 (不过现在github规定不能https提交了)
注意 github https 和 ssh 连接的不同使用。
git@github.com:
https://github.com/
如:
git@github.com:ruozhiertong/phpDemo.git
https://github.com/ruozhiertong/UULP.git
ssh要配置公钥和私钥。 配置之后提交不用密码了。
https要每次都输入github的账号和密码。
本地repository。
远程github repository。
- 如果只有本地仓库,没有远程,那么需要在远程建立仓库后,将本地和远程关联,再同步。
- 如果只有远程,没有本地,那么可以直接从远程clone。 或者本地创建后,将本地和远程关联,同步。
- 新建本地仓库
- git init .
新建远程github仓库。
本地和远程进行连接
git remote add xxx url
git remote set-upstream-to xxxxxxx
git remote -v
具体信息 也可以查看仓库下的 .git/config.
如:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote “origin”]
url = git@github.com:ruozhiertong/phpDemo.git
fetch = +refs/heads/:refs/remotes/origin/
[branch “master”]
remote = origin
merge = refs/heads/master
git push oringin master //将master分支push到远程 origin 的master分支上。
git push origin HEAD:master //将当前分支push到远程的master分支上。
Push the current branch to the remote ref matching master in the
origin repository. This form is convenient to push the current
branch without thinking about its local name.
git status
git add
git commit -m
git push
git pull
git log
git diff xx xx
如果本地branch和远程不一致,不能直接用git push。
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:main
To push to the branch of the same name on the remote, use
git push origin master
To choose either option permanently, see push.default in ‘git help config’.
其他操作
同一台多账号github。
https://blog.csdn.net/qq_43199318/article/details/103469792
https://blog.csdn.net/littleRpl/article/details/109801707
0.生成两套ssh私钥和公钥。 一般在~/.ssh目录下。
ssh-keygen -t rsa。
1.添加
ssh-add ~/.ssh/id_rsa_github1
ssh-add ~/.ssh/id_rsa_github2
2.a测试
ssh -T git@github.com
ssh -T git@two.github.com
2.b
git clone
git clone git@three.github.com:mswanghang/hello-world-javascript-action.git
3.修改 仓库下 .git/config 文件,将 对应的远程url改到对应的ssh配置。
如:
[remote “origin”]
url = git@two.github.com:fightingcoder2022/haxvps.git
fetch = +refs/heads/:refs/remotes/origin/
如
[remote “origin”]
url = git@github.com:ruozhiertong/phpDemo.git
fetch = +refs/heads/:refs/remotes/origin/