1. 本地项目git初始化
输入命令: git init
2. 本地提交
输入命令: git commit -m "你的注释"
3. 连接远程github仓库
输入命令: git remote add origin 你的仓库地址
4. 远程仓库有README.md文件(无则不用)
执行命令:git pull --rebase origin master
5. 提交到远程仓库的主分支
执行命令:git push -u origin master
2. 创建分支
1、在当前分支下(一般是master分支),创建muscleape的本地分支分
$ git checkout -b muscleape
Switched to a new branch ‘muscleape’
2、将muscleape分支推送到远程
$ git push origin muscleape
Everything up-to-date
3、将本地分支muscleape关联到远程分支muscleape上
$ git branch --set-upstream-to=origin/muscleape
…
…
…
Branch ‘muscleape’ set up to track remote branch ‘muscleape’ from ‘origin’
4、查看本地分支和远程分支的映射关系
$ git branch -vv
muscleape f938a3d8e9 [origin/muscleape: gone] 测试test
5、查看远程分支
$ git branch -r
origin/muscleape
6、查看本地各个分支目前最新的提交
$ git branch -v
muscleape f938a3d8e9 测试test
7、查看远程各个分支目前最新的提交
$ git branch -r -v
origin/muscleape f938a3d8e9 测试test
git修改项目地址
以下均以项目git_test为例:
老地址:http://192.168.1.12:9797/john/git_test.git
新地址:http://192.168.100.235:9797/john/git_test.git
远程仓库名称: origin
方法一 通过命令直接修改远程地址
进入git_test根目录
git remote 查看所有远程仓库, git remote xxx 查看指定远程仓库地址
git remote set-url originhttp://192.168.100.235:9797/john/git_test.git
方法二 通过命令先删除再添加远程仓库
进入git_test根目录
git remote 查看所有远程仓库, git remote xxx 查看指定远程仓库地址
git remote rm origin
git remote add originhttp://192.168.100.235:9797/john/git_test.git
方法三 直接修改配置文件
进入git_test/.git
vim config
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
precomposeunicode = true
[remote “origin”]
url = http://192.168.100.235:9797/shimanqiang/assistant.git
fetch = +refs/heads/:refs/remotes/origin/
[branch “master”]
remote = origin
merge = refs/heads/master
修改 [remote “origin”]下面的url即可
作者:郝赫
链接:https://www.jianshu.com/p/ebc6b1a026c2
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。