首先在github上创建仓库,创建成功后可以看到仓库地址。
git config --global user.name "Your Real Name"
git config --global user.email you@email.address
//first commit
git init //把这个目录变成Git可以管理的仓库
git add README.md //文件添加到仓库
git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了
git commit -m "first commit" //把文件提交到仓库
git remote add origin 仓库地址 //关联远程仓库
git push -u origin master //把本地库的所有内容推送到远程库上
//之后的更新
git add README.md //文件添加到仓库
git commit -m "first commit" //把文件提交到仓库
git push -u origin master //把本地库的所有内容推送到远程库上
补充:关于撤销 参考
https://blog.youkuaiyun.com/u011441473/article/details/80774302
参考资料:https://www.cnblogs.com/specter45/p/github.html
https://blog.youkuaiyun.com/chaihuasong/article/details/37911723
-------------------2020.02.17更新------------------
[若git push -u origin master失败,报错! [rejected] master -> master (non-fast-forward)]
先执行git pull
然后再执行 git push --force origin master 替换原先的git push -u origin master
问题原因:If another person has pushed to the same branch as you, Git won't be able to push your changes. You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally
github官网介绍:Dealing with non-fast-forward errors
https://help.github.com/en/github/using-git/dealing-with-non-fast-forward-errors
$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work
Or, you can simply use git pull to perform both commands at once:
$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work