1.git是通过ssh协议连接远程git服务器的,所以在登录ssh之前需要生成ssh密钥对将本地和远程git服务器连接起来:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
,其中your_email@example.com
替换为你的邮箱地址。2.接下来配置ssh密钥,即将上一步产生的密钥添加到git服务器上,配置完成后,现在你可以通过SSH登录到Git服务器上的仓库了。
3.配置git客户端,让其使用SSH登录进行一次登录。可以按照以下步骤进行操作:
git config --global user.name "Your Name"
,将Your Name
替换为你的用户名。git config --global user.email "your_email@example.com"
,将your_email@example.com
替换为你的邮箱地址。git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa"
,将~/.ssh/id_rsa
替换为私钥的路径。4.验证配置:
ssh -T git@example.com
,将git@example.com
替换为你的Git服务器地址。通过以上配置,我们能够使用Git客户端连接到Git服务器上的仓库,进行诸如克隆、推送、拉取等操作。
1.创建仓库:
git init
:初始化一个git仓库git clone <url>
:clone一个git仓库2.git config
,我们可以通过git config
来配置用户名和邮箱地址,便于我们将代码提交到远程仓库,具体格式如下:
git config --global user.name '你的用户名' git config --global user.email '你的邮箱'
3.git add
,git add
命令可将文件添加到缓存,如新项目中,添加所有文件很普遍,可以使用如下命令:
git add .
当然我们也可以指定某一类文件,如将java文件添加到缓存中,可以使用如下命令:
git add *.java
4.git status
,我们可以使用 git status
命令来查看相关文件的状态,直接执行如下命令:
git status
5.git commit
,git commit
将缓存区内容添加到仓库中,可以在后面加-m选项,以在命令行中提供提交注释,格式如下:
git commit -m "第一次版本提交"
如果你觉得 每次 commit之前要add一下,想跳过add这一步,可以直接使用 -a选项,如:
git commit -am "第一次版本提交"
6.git branch
,git branch
可以查看分支,也可以创建分支,如果没有参数时,git branch会列出你在本地的分支;如果有参数时,git branch
就会创建改参数的分支。如果要查看分支,命令格式如下:
git branch
当我们想创建分支时,可以在后面加参数,命令格式如下:
git branch branchname
7.git checkout (branchname)
,git checkout
可以切换分支,命令格式如下:
git checkout branchname
8.git merge
,git merge
命令可以将任意分支合并到到当前分支中去,命令格式如下:
git merge branchname
9.git branch -d (branchname)
,git branch -d
可以删除分支,删除分支命令格式如下:
git branch -d (branchname)
10.git remote add
,git remote add
可以添加一个远程仓库,其命令格式如下:
git remote add [alias] [url]
参数[alias]为别名, [url]为远程仓库的地址,如:我们可以将https://github.com/qtqt/test.git
11.git remote
,git remote
可以查看当前有哪些远程仓库;
12.git fetch
可以提取远程仓库的数据,如果有多个远程仓库,我们可以在后面加仓库的别名,git pull
命令用于从另一个存储库或本地分支获取并集成(整合),在默认模式下,git pull
是git fetch
后跟git merge FETCH_HEAD
的缩写.
13.git push
,git push
推送你的新分支与数据到某个远端仓库命令,格式如下:
git push -u [alias] [branch]
参数[alias]为别名, [branch]为远程仓库项目的分支;
14.git remote rm
,git remote rm
删除远程仓库,格式如下:
git remote rm [别名]
1.error: failed to push some refs to 'https://github.com/zzwcreator/chatglm_caption.git' 问题原因:远程库与本地库不一致造成的,在hint中也有提示把远程库同步到本地库就可以了 解决办法:使用命令行:
git pull --rebase origin master
本文作者:zzw
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 License 许可协议。转载请注明出处!