cd 进入项目文件夹
git init (初始化git)
git add index.html (添加到暂存区)
git commit -m "index"(从暂存区添加到本地仓库,双引号里写描述)
git remote add origin url (添加远程仓库的关联,url是仓库地址)
git push -u origin master (将本地的master分支推送到origin主机,同时指定origin为默认主机,第一次git push,git push不行,后面要加参数。此后可不加参数)
可能遇到的问题:
使用git push -u origin master时报错:
fatal: unable to access 'https://github.com/lyl22222/2233.git/': Failed to connect to github.com port 443: Timed out
解决:
配置 git 的代理:
git config --global http.proxy "127.0.0.1:1080"
git config --global https.proxy "127.0.0.1:1080"
然后可能会遇到:
fatal: unable to access 'https://github.com/lyl22222/2233.git/': Failed to connect to 127.0.0.1 port 1080: Connection refused
然后取消代理:
git config --global --unset http.proxy
git config --global --unset https.proxy
就可以了,
查看所有分支:git branch
创建分支:git branch [名字]
切换分支:git checkout [名字] / git switch [名字]
创建并切换分支:git checkout -b [名字] / git switch -c [名字]
合并分支:git merge [name]
删除分支:git branch -d [名字]
创建新的分支testing,
git branch testing
git checkout testing
git add aa.js
git commit -m "aa.js"
git push --set-upstream origin testing / git push -u origin testing (将分支与远程仓库建立连接)
testing分支有变动,需合并到主分支上
git checkout testing
git pull
git checkout master (切换到主分支)
git merge testing
git push
当master分支有变动时,更新到testing分支上
git checkout master
git pull
git checkout testing
git merge master
git push