最近刚刚开始使用Git,对于所有的一些命令以及环境都不是很熟,这里个人总结一下。
1.git的安装和初次使用配置
ubuntu安装git下直接命令
sudo apt-get install git
git一般和repo一起使用,所以需要配置repo
#you can rename the dir according to your habits
mkdir [devDir] && cd [devDir]
#--------------------------------------------------------
#references: https://source.android.com/source/downloading.html
#install repo
#you can change the dir but you must ensure the dir is included in your PATH
mkdir ~/bin
PATH=~/bin:$PATH
#Download Repo and ensure it is executable
#make sure the dir the same as before
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
初次使用git需要配置user.name以及user.email
#First time must set user.name and user.email
git config user.name "[username]"
git config user.email [username@example.com]
初始化repo,也就是通过ssh与相应的git服务其建立链接
#initialize repo
repo init -u ssh://[url].git
最后一部同步代码
#until now you can Sync codes from the git
repo sync
至此相应的开发代码已经同步到对应的目录[devDir]下。
注:以上命令中,带有"[ ]"的都是需要根据实际情况替换的。
2.开发过程中使用git的一般流程
同步代码,前面已经说过;
创建分支
git branch [branch] --track origin/[branch]
关联分支
git branch [branch] --set-upstream origin/[branch]
查看分支状态
git branch
切换到[branch]分支
git checkout master
将修改完毕的code加入到暂存区
git add .
查看当前暂存区状态
git status
将暂存区的修改提交到本地库
git commit -s -m "comment"
repo upload .
慢慢熟练,不断完善中~~~~~~~加油!!!!