记录利用Git操作github的操作。
git --config -global user.name <your github user name> #配置用户信息
git --config -global user.email <your github email> #配置用户信息
git init <name> #name是可选的。有name表示在当前文件夹建立一个名为name的repository。没有那么表示将当前文件设为repository。
git status #查看本地repository中包含的文件
git add filename #建立连接
git status #这次可以发现和上次不一样了
git commit -m "message"
git remote add origin ADDR
git -u push origin master #master 是repository的默认分支,若远程repository为空的话,要-u
git push origin master #将文件推送到远程repository
git push origin <localdir>:<remotedir> #将local dir文件推送到remote dir分支
git clone <ADDR> #克隆ADDR的文件到本地
git checkout <branchname> #跳转到branchname分支
git branch <branchname> #新建branchname分支
git branch -r #查看分支
git checkout -b <branchname> #跳转到新建的branchname分支
push到其他分支应该修改master就好了。我出现了这个错误:
$ git push origin master
To https://github.com/LiShanCheer/leaning.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/LiShanCheer/leaning.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
参考这个文件 解决了。这个是由于仓库中有文件,而且本地中没有;需要先整合才行。这样本地会包含远程repository中的全部文件。使用下面的命令:
git pull --rebase origin master
git push origin master #然后再使用push命令就可以了
网友评论