Linux下Git常用操作命令【创建、提交、推送、同步】

艺帆风顺 发布于 2025-04-03 75 次阅读


1、在目录下创建文件

[root@localhost citest]# pwd/git/citest[root@localhost citest]# touch ci.sh

2、初始化git仓库

git init

3、添加项目文件到Git仓库:添加当前目录下所有文件

git add .

4、提交更改

git commit -m "Initial commit"

5、将本地存储库与Gogs存储库关联:

git remote add origin https://git.erp12580.com/yinling/citest

6、推送本地存储库中的更改到Gogs存储库

git push -u origin master

7、删除已经存在的远程origin,可以使用以下命令:

git remote remove origin

8从远程仓库同步代码

git pull

9、报错信息处理

[root@localhost citest]# git push -u origin master提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更提示:(如 'git pull ...')。提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。

    解决:

    拉取远程仓库的变更:

git pull origin master

    再将合并后的本地分支推送到远程仓库

git push origin master