Create git project

Create a directory:

mkdir gitTest
cd gitTest

Initialize git

git init

After executing the above command, there will be an additional .git file (hidden file) under the gitTest folder
In Code Cloud-Open Source China Code Hosting PlatformAdd a project, you can find the project git address on the project homepage, as shown in the lower right corner of the picture below, just copy it
Write picture description here

Go back to the command line window just now, execute the command, and add the remote warehouse (the following URL is the git address of the project you just copied)

git remote add origin https://git.oschina.net/cxbin/iSwfitProject.git

If the error "fatal: remote origin already exists." appears, please run the following command to remove the warehouse, and then execute the add remote warehouse command again.

git remote remove origin

Related commands

git remote  #列出已存在远程仓库
git remote show origin #显示origin仓库信息
git branch -r  #列出远程分支
git branch  #列出远程和本地分支

If the branch is not found, you can use the following method to create a branch

1.命令行(推荐)
git pull origin master

2.打开项目目录下的\.git\config文件,追加一下内容(不推荐)

格式:[branch "<本地分支>"]
        remote = <远程仓库>
        merge = refs/heads/<远程分支>

示例:[branch "master"]
        remote = origin
        merge = refs/heads/master

Set up tracking remote branch

格式:git branch --set-upstream-to=<远程仓库>/<远程分支> <本地分支>
示例:git branch --set-upstream-to=origin/master master

The purpose of setting up tracking is to simplify pull and push commands without having to bring remote warehouses and remote branches every time.

At this point, the git project has been created, and you can use pull and push to submit the code.

You may also encounter the error "fatal: refusing to merge unrelated histories" when you do your first git pull. This is because they are two different projects. To merge two different projects, you need to add –allow-unrelated -history

git pull --allow-unrelated-histories

Guess you like

Origin blog.csdn.net/chenxiabinffff/article/details/55805336