The article is primarily addressed to those who have already
If you are not yet ready to boldly cross out all the points listed above, then it is recommended that you first read this article:
Everyone else is offered 2 ways to link a local repository with a remote one:
In both cases, you will need to create a new repository.
First of all, it is strongly recommended to make your life easier in the future and return the default name of the main branch back to master. This will allow you to avoid confusion in names and unnecessary errors in further work. Because the name master is the default branch name in newly created local repositories.
To do this, in GitHub, click on the icon of your avatar in the upper right corner, then select "Settings".
On the page that opens, in the "Code, planning, and automation" section select "Repositories" and in the "Repository default" section branch" (Default repository branch) replace the value of main with master. (And, of course, don’t forget to click the Update button afterwards!)Now you can create new repositories. To do this, we go to the reppository list and press the New button. It is not at all necessary to select any options (especially in the first case!). This procedure is discussed in more detail in the video (link at the end of the article).
If you chose this method, it means that your local machine already has a working folder, into which you have already entered in the terminal
git init
And perhaps it even has its own commit history.
In this case, copy the SSH address of the created repository and enter the command in the local repository terminal:
git remote add origin <your repository name>
If there were any changes to the project, you need to write them to the local repository:
git add --all && git commit -m "your commit"
And after that add all this information to the deleted one:
git push -fu origin master
Important! The -f prefix is used if you have already written something to a remote repository, but you do not need this information. Therefore, writing this update to the local repository will completely overwrite all information in the remote repository.
That's all, actually - the remote repository is now linked to the local one and ready to go!
This option is somewhat simpler to implement and is ideal for those who have not yet switched from git to the basics.
To implement it, you will need to select in the terminal window the location where the local repository will be located, and then enter only one command:
git clone <your repository name>
The initialization of the local repository and its binding to the remote one are successfully completed and you can start working. The only addition: to create commits after making changes to the project, you will first need to “go down” 1 level down - to the project folder (see video)
You can find out more about all the information presented in the article in this video (RU voice):