Bo2SS

Bo2SS

3 Simple Synchronization of Git and GitHub

30 | Register a GitHub Account#

Registration URL: https://github.com/signup

Use your email to register.

31 | Configure Public and Private Keys#

Scenario: Want to use the SSH protocol instead of the HTTP/HTTPS protocol.

Advantage: No need to enter a username and password, successful identity verification is based on matching public and private keys.

Steps🌟: Adding a new SSH key to your GitHub account——Github Docs

  • Generate local public and private keys👉Upload the public key to GitHub

Article I wrote about SSH principles: Implementation and Essential Considerations of Passwordless SSH Login——DoubleLLL3

32 | Create a Personal Repository on GitHub#

Steps🌟: Create a repo——Github Docs

image

❗️:

  • Owner can also choose the organization you belong to
  • Public visibility means it is visible to others, but commit permissions need to be configured separately
  • README file helps the repository be indexed by search engines
  • If you already have a README file locally, it is not recommended to check "Add a README file" to avoid conflicts
  • Licenses: Content without a license is protected by copyright by default

33 | Synchronize Local Repository with 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.

Check the list of remote servers using git remote -v:

Adding successful!

At this point, git push github --all will result in an error:

Apart from the master branch, all other branches are successfully pushed.

Git provides a clear error message: a pull is required.

PS: If the remote branch is not an ancestor of the local branch, they are not fast-forwards. Conversely, if they are fast-forwards, they usually need to be resolved through rebase or merge.

So, pull first: git fetch github

Successfully fetched the master branch from the remote github. Now, check the branch graph using gitk --all:

It can be seen that the master branch on the github side is not related to the local master branch.

Now, associate the two master branches through rebase or merge:

git checkout master : Make sure to switch to the master branch first

git merge github/master --allow-unrelated-histories : Merge the remote master branch into the local master branch, and enter the commit message.

⚠️: --allow-unrelated-histories is needed to explicitly allow the merging of two unrelated branches.

Now, check the branch graph again using gitk --all:

The relationship is successfully established, and the latest commit of the master branch has two parent commits.

🌟 : git pull includes both git fetch and git merge, and git pull --rebase includes both git fetch and git rebase.

Finally, push the master branch: git push github master


Let's take a look at our GitHub repository:

The newly added file looks familiar, doesn't it~

So far, we have interacted with GitHub!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.