一、你是第一个提交代码到github/gitlab上的人:
git init //初始化本地仓库 git add . //将文件加到暂存区 git commit -m "first commit" //将文件提交到本地仓库 git remote add origin git@github.com:***/test.git //链接github上的远程仓库 git push -u origin master //将本地仓库的文件推送到远程仓库
二、已经有人提交了代码到github/gitlab上:
git clone git@github.com:***/test.git //将远程仓库的内容克隆到本地
之后的常用操作:
git pull origin master //从远程仓库拉去最新的代码,并合并
git add .
git commit -m '注释'
git push -u origin master
一些相对不常用但很有用的操作:
git branch -a //查看所有分支,包括远程的
git branch newBranchName //在本地创建新的分支
git checkout newBranchName //切换到新建的分支
git push origin newBranchName:newBranchName //将分支内容内容推送到远程仓库,并在远程仓库新建对应的分支
git clone -b newBranchName git@github.com:***/test.git //克隆远程仓库相应分支的代码
以上操作是作为前端的我常用到的,我个人习惯在master分支上存放静态页面的源码,并在github上展示静态页面;然后在另一个分支里存放在静态页面上加了各种功能的源码作为存档,所以总结一下,希望对你们有用!