git 命令行
…或者在命令行上创建一个新的存储库
参考:https://www.runoob.com/w3cnote/git-guide.html
首先在本地创建ssh key
ssh-keygen -t rsa -C "your_email@youremail.com"
后面的your_email@youremail.com
改为你在github上注册的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/
下生成.ssh
文件夹,进去,打开id_rsa.pub
,复制里面的key
。
回到github上,进入 Account Settings(账户配置),左边选择SSH Keys,Add SSH Key,title随便填,粘贴在你电脑上生成的key。
为了验证是否成功,在git bash下输入
ssh -T git@github.com
把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们
git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"
进入要上传的仓库,右键git bash,添加远程地址:
git remote add origin git@github.com:wzdyt/HelloWorld.git
创建新的 git 仓库
git init
创建一个本地仓库的克隆版本
git clone git@github.com:wzdyt/HelloWorld.git
```shell
git add
加入中间区
git status 查看当前状态
git commit -m "first commit" 加入本地git仓库
git push 提交到github仓库
执行如下命令以将这些改动提交到远端仓库:
git push origin master
可以把 master 换成你想要推送的任何分支。
git checkout -b 分支名 创建分支
git checkout 分支名 切换分支
git branch -a 查看所有分支
git branch -m 分支名 重新命名分支名称 -M 强制修改
git push --set-upstream origin 分支名称 远程仓库没有该分支的情况下 该命令会push 并在远程仓库创建分支
git pull 命令用于从远程获取代码并合并本地的版本。
git pull 其实就是 git fetch 和 git merge FETCH_HEAD 的简写。
命令格式如下:
git pull <远程主机名> <远程分支名>:<本地分支名> 当团队合作协作时,git pull可以保证本地和远程代码一致
要合并其他分支到你的当前分支(例如 master),执行:
git merge <其他分支名称>
参与讨论
(Participate in the discussion)
参与讨论