Git 的使用
![](/images/avatar.png)
分布式版本控制系统,适合个人中小企业使用
Installation
sudo pacman -S git |
Usage
基本配置
配置git 的用户名和邮箱:
git config --global user.name "dionysen" |
新建一个仓库
Initiate git repository on the local:
git init |
or set the file path:
git init path/to/repo |
A repository was created, but it is empty.
You can add some files to the repository:
git add [filename] // e.g. "git add ." |
Then you add this files to the stages and you need to commit this to the repository.
git commit -a -m "Changed some files" |
-a
does not commit any new files.-m
means that you should give the commit message.
Add a remote repository:
git remote add origin git@gitee.com:sential/source.git |
Push the local repository to the remote repository:
git push origin master |
- 若要在一个新的设备上使用远程仓库,首先将此仓库克隆到本地:
git clone git@gitee.com:sential/source.git |
添加个人公钥
然后按照 gitee
上的提示添加个人公钥:
ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com" |
与远程仓库同步
每次编辑时要执行。
git pull origin master |
或者每次编辑完成后,在另一处pull
一次,那样不用每次编辑前都要再拉去一下了。
写两个脚本自动拉取和提交。
- 当没有拉取最新版本的远程仓库同时又修改了本地仓库时,拉取会提示错误,需要选择合并或者放弃某一端,如果放弃本地仓库,执行以下命令:
git reset --hard |
分支切换
查看分支:
git branch -a # 查看远程分支 |
新建分支:
git checkout -b linux origin/linux |
之后即可正常使用,切换分支使用命令:
git checkout main # 切换到主分支 |
- 本文标题:Git 的使用
- 创建时间:2023-05-25 17:34:01
- 本文链接:2023/05/25/note/Programming/evn/Git/
- 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
显示评论