Bo2SS

Bo2SS

3 Simple Synchronization between Git and GitHub

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

image

❗️:

  • 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

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.

image

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:

image

Successfully added!

At this point, git push github --all, pushing directly from local will result in an error:

image

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

image

Successfully pulled the remote GitHub master branch; at this point, check the branch graph with gitk --all:

image

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:

image

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:

image

The newly added files look quite familiar, right?

At this point, we have already interacted with GitHub!

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