Several ways to add code to the git repository

There are several situations for submitting a new code project to the git server:
1) There is a git library first, and then the code is added: create an empty warehouse on the server and pull it down locally. After creating and writing the source files, commit the code.
2) Existing local code, add it to the remote code library: the local code has been created and developed, init a local git library in the code directory, and then add the git remote code library link to the local code library, so that it can be submitted normally code up.
3) Switch from one git library to another git library:
(1) Use git clone --bare to download a bare git library, and then set it to a new url through remote set-url. In this way, the original library can be The commit records and tags are submitted to the new git repository.
(2) If you don’t want the original submission record, clone the code normally, delete .git, and submit the code according to the process of method 2).

Here are a few examples:

1) There is a code base first, and then the code is added

git clone https://your_git_url/path/to/project.git
cd project
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

2) Add the existing code to the git library

cd existing_folder
git init
git remote add origin https://your_git_url/path/to/project.git
git add .
git commit
git push -u origin master

3) Import code from other git libraries

git clone --bare https://other_git_url/path/project.git local_path
cd local_path
git remote set-url origin https://your_git_url/path/to/project.git
git push origin --tag && git push origin --all

Use https and ssh to synchronize code, the difference in url:
url used by https: git clone https://your_git_url/path/to/project.git
url used by ssh: git clone git@your_git_url:path/to/project.git

Guess you like

Origin blog.csdn.net/yinminsumeng/article/details/129331339