—————— git 基本配置 ——————
// 本地 git 配置文件:
vim ~/.gitconfig
—— 里面有个 email 的配置特别重要。
// 在 github 上的使用:
1、本地生成 ssh 秘钥,请参考:MAC下生成密钥,并使用ssh密钥登录
2、将秘钥的公钥部分复制,并粘贴到 settings/SSH and GPG keys里面。
// 测试:
ssh -T git@github.com
如果是第一次的会提示是否continue,输入yes就会看到:You've successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
// 设置name 和 email,git每次 commit 都会记住它们:
git config --global user.name "林烽" git config --global user.email "349017128@qq.com"
// 1、本地不存在项目,直接检出仓库:
git clone http://git.weilaigongzuo.com/dongxizhizao/admin.git admin //远程仓库克隆到本地并重命名为admin cd admin //切换到目录下 touch README.md // 创建某文件 git add README.md //将某文件添加到版本管理 git add . //所有变化提交到暂存区 git commit -m "add README" //提交到本地仓库 git push -u origin master //push到远程仓库
git pull //更新远程代码到本地
// 本地存在项目,把本地项目添加到远程仓库:
cd zhongjun // 进入本地仓库 git init // 初始化 git git remote add origin http://git.weilaigongzuo.com/dongxizhizao/admin.git //添加对应远程仓库 git add . // 把所有变化提交到暂存区 git commit -m "Initial commit" //提交到本地仓库 git push -u origin master //push到远程仓库
// 存在 git 仓库的常用操作
cd existing_repo //切换到存在的仓库 git remote rename origin old-origin // 重命名远程仓库的名字 git remote add origin http://git.weilaigongzuo.com/dongxizhizao/admin.git // 添加对应远程仓库 git pull // 更新远程代码到本地 git push -u origin --all // 把所有版本push 到远程仓库 git push -u origin --tags // 把某个分支版本 push 到远程仓库
//常用:
git branch //查看本地分支 git branch -a //查看远程分支 git checkout -b agrochemical origin/agrochemical //切换分支 git branch -a //查看所属分支 git reset --hard HEAD^ //回退到上个版本 git reset --hard HEAD~3 //回退3个版本 git checkout -b branch //在当前分支创建新的分支
git merge branch //将 branch分支的修改合并到 master 上
git branch -d branch //将分支 branch 删除
git push origin --delete <分支名> // 删除远程的分支
git add . // 把所有变化提交到暂存区 git commit -m "Initial commit" //提交到本地仓库 git push -u origin master //push到远程仓库
//分支
git branch -a //查看远程所有分支 git checkout -b branch origin/branch //切换分支 git branch -a //会发现当前分支已经切换 git checkout master //切换回 master 分支
—————— 占位符