1。创建github账号 浏览器搜索github或直接打开网址https:github。com进入github如下账号创建页面 具体步骤可参考官网的教程地址:https:help。github。comarticlescreatearepo 如果一切顺利,输入邮箱、密码等,大约30秒即可完成账号创建。 2。创建仓储: 仓储(repository),理解为管理各种文件的仓库。进入个人github页面,点击右上角头像,在下拉栏选 择Yourrepositories,随后页面跳到仓储面完成创建。 如创建仓储blog,git地址:https:github。comuser2itemsblog。git 3。创建本地3。1安装Git: 首先我们需要先下载Git,这里最好下载最新版本的Git,网址:https:gitscm。comdownloads,安装时如果没有特殊需求,一直下一步就可以了,安装完成之后,双击打开GitBash。 3。2Git设置: 配置:cdXXXuser2items gitconfigglobaluser。name此处为你的github的用户名gitconfigglobaluser。email此处为你的邮箱gitconfigglobaluser。nameXXXXXgitconfigglobaluser。emailXXXX。com 这里输入的用户名和电子邮件是任意的,这些信息只是用来记录是谁进行了修改。可以通过输入gitconfiglist查看配置的信息。 公钥: sshkeycd。ssh,查询是否存储公钥sshkeygentrsaC此处为你的邮箱sshkeygentrsaCXXXXX。com 创建公钥名称为user2items(可以不写)Enterfileinwhichtosavethekey(cUsersDELL。sshidrsa):user2items 发现有2个文件:user2items。pub和user2items 记事本打开user2items。pub,复制内容到github: 点击头像进入SettingsSSHandGPGkeysNewSSHkey,将复制的信息粘贴到该处。 测试: sshTgitgithub。comHiuser2items!Youvesuccessfullyauthenticated,butGitHubdoesnotprovideshellaccess。 3。3上传代码到远端仓储: gitinit初始化gitadd。添加当前位置的全部文件,注意。gitremoteaddoriginxxx添加远端仓储,origin为远端在本地的服务主机名称,xxx为远端url地址gitcommitm注释语句提交到本地仓储gitpushuoriginmaster从本地上传github 4。git常见命令 1)远程仓库相关命令 检出仓库:gitclonehttps:github。comuser2itemspaperClub。git 查看远程仓库:gitremotev 添加远程仓库:gitremoteadd〔name〕 删除远程仓库:gitremoterm〔name〕 修改远程仓库:gitremoteseturlpush〔name〕〔newUrl〕 拉取远程仓库:gitpull〔remoteName〕〔localBranchName〕 推送远程仓库:gitpush〔remoteName〕〔localBranchName〕 2)分支(branch)操作相关命令 查看本地分支:gitbranch 查看远程分支:gitbranchr 创建本地分支:gitbranch〔name〕创建后不会自动切换为当前分支 切换分支:gitcheckout〔name〕 创建新分支并立即切换到新分支:gitcheckoutb〔name〕 删除:gitbranchd〔name〕d选项只能删除已经参与了合并的分支,对于没有合并的分支是无法删除的。如果想强制删除一个分支,可以使用D选项 合并分支:gitmerge〔name〕将名称为〔name〕的分支与当前分支合并 创建远程分支(本地分支push到远程):gitpushorigin〔name〕 删除远程分支:gitpushorigin:heads〔name〕或gitpushorigin:〔name〕 参考:https:blog。csdn。netdengsilinmingarticledetails8000622