30 | Register a GitHub Account#
Registration link: https://github.com/signup
You can register using your email.
31 | Configure SSH Keys#
Scenario: Want to use the SSH protocol instead of the HTTP/HTTPS protocol.
Advantage: No need to enter a username and password; matching public and private keys means authentication is successful.
Steps🌟: Adding a new SSH key to your GitHub account — GitHub Docs
- Generate public and private keys locally 👉 Upload the public key to GitHub
I wrote an article about the principles of SSH: Implementation and Essential Thoughts on Passwordless SSH Login — DoubleLLL3
32 | Create a Personal Repository on GitHub#
Steps🌟: Create a repo — GitHub Docs
❗️:
- The Owner can also choose the organization you belong to
- Public is only visible externally; submission permissions need to be configured separately
- A README file helps the repository be indexed by search engines
- If there is already a README file locally, it is not recommended to check Add a README file to avoid conflicts
- Licenses: Content without a License is by default copyright protected
- The MIT License is a permissive License that allows others to do anything with your code, as long as they credit you and do not hold you liable for any issues that arise from its use
- Reference How to Choose an Open Source License for Your GitHub Project? — Zhihu
33 | Synchronize Local Repository to GitHub#
Steps: Add remote server -> Pull and merge ❗️ -> Push
Add remote server:
git remote add github [email protected]:doubleLLL3/git_learning.git
Here, github
is the remote alias, followed by the corresponding HTTPS or SSH address, which can be copied from GitHub.
In the last section, I chose to create the repository by adding an MIT License. (Setting the stage for the following content)
Check the list of remote servers with git remote -v
:
Successfully added!
At this point, git push github --all
, pushing directly from local will result in an error:
Other branches were successfully pushed except for the master branch.
Git provides a clear prompt for the error: you need to pull first.
PS: If the remote branch is not an ancestor of the local branch, then they are not fast-forwards. Conversely, they are in a fast-forwards relationship, which generally needs to be resolved through rebase
or merge
.
So pull first: git fetch github
Successfully pulled the remote GitHub master branch; at this point, check the branch graph with gitk --all
:
It can be seen that the master branch on GitHub has not established a relationship with the local master branch.
At this point, relate the two master branches through rebase or merge:
git checkout master
: Ensure you switch to the master branch first
git merge github/master --allow-unrelated-histories
: Merge the remote master branch into the local master branch, just enter the commit message.
⚠️: You need --allow-unrelated-histories
to explicitly allow merging of the two branches that are unrelated.
Now check the branch graph again with gitk --all
:
The relationship has been successfully established, and the latest commit of master now has two parent commits.
🌟: git pull
includes both git fetch
and git merge
, and you can also use git pull --rebase
which includes git fetch
and git rebase
.
Finally, push the master branch: git push github master
Now let's take a look at our GitHub repository:
The newly added files look quite familiar, right?
At this point, we have already interacted with GitHub!