Git初始化项目强制推送

1. 在项目根目录创建两个文件

README.md.gitignore

2. 初始化git本地仓库

git init

3. 将所有文件添加至暂存区

git add .

4. 进行首次提交

git commit -m 'firstcommit'

5. 添加远端仓库

git remote add origin git@gitee.com:testProject/test.git

注意 此处的 git@gitee.com:testProject/test.git 是远端仓库地址,实际操作中要写你们自己的仓库地址,前往不要直接复制!
如果不小心添加错远端仓库,可使用如下命令先删除远端仓库地址,然后再执行添加远端仓库操作!

git remote remove origin

查看远端仓库地址的方法
查看远端仓库地址的方法

6. 从远端拉取

git pull

7. 强制推送至远端仓库

git push -u -f origin master

8. 大功告成

再次回到Gitee网页仓库管理,刷新即可看到最新提交的代码。

附件:

.gitignore

.gitignore是git忽略文件配置,符合条件的文件将被git忽略,例如.idea目录、class文件等。

*.class

#package file
*.war
*.ear

#kdiff3 ignore
*.orig

#maven ignore
target/

#eclipse ignore
.settings/
.project
.classpatch

#idea
.idea/
/idea/
*.ipr
*.iml
*.iws

# temp file

*.log
*.cache
*.diff
*.patch
*.tmp

# system ignore
.DS_Store
Thumbs.db

添加新评论

评论列表