“This is the 13th day of my participation in the First Wenwen Challenge 2022.First challenge in 2022”
GitHub distributed version control system
Git and Github
Git:
Version management tool is a version management tool that can be used only locally when your computer is not connected to the Internet
Github
- Github, this is a website, is every programmer to write their own procedures, can be built on Github online
Remote warehouse
You can submit your code online every time you submit it, so that every time you submit it, people can see your code and people can modify your code for you, and that kind of thingOpen sourceThe way is very convenient for programmers to communicate and learn.
To sum up, Git can be thought of as a piece of software that helps you write better programs, while Github is a website that helps programmers communicate and learn from each other.
Using a lot
- Github has walls and is slow
In China, we usually use Gitee
- Companies sometimes build their own use:
gitlab
The server
1. Create a Github account first
github This is developed by foreigners so pure English... You can use the browser to translate..
2. Create an SSH Key
Open Git Bash, type the following command, and press EnterSsh-keygen -t rsa -c 'own mailbox'
Before using git, ensure that your local git account/email address matches github
Configure the global user name
git config --global user.name 'Enter a user name'
Configure the global mailbox
git config --global user.email '[email protected]'
The user name and mailbox can also be configured for each project.
Copy the code
Next go to C:\Users\AdministratorWindows: System disk/user/administrator/directory
- You’ll find an extra.ssh folder where the generated key is located.
id_rsa
Is its own key,id_rsa_pub
A public key is an external keyGive it to github that needs to be connected, and you'll be connected.
3. Add a local public key to Github
Go to github Settings and find SSH and GPG Keys
4. Test the connection
ssh -T [email protected]
Enter the command to test the connection between the local Git and Github test,,,, The first test connection requires input validationConfirm the connection
: yes/noType yes!
- At this point inC:\Users\Administrator.sshOne was born under the path
known_hosts
The file - Github has established a connection with github and has been identified.
Git — > Upload — > Githubpush
Upload your local project to Github
You must first create an empty repository on Github.
I created a CSwrokTest directory
.
Establish a connection with the local warehouse
This page is displayed when it is first created:
- This is an empty remote repository that needs to be connected to the local repository to use!
- You can connect according to the command provided by the above authorities!
I prepare a local warehouse work in advance
The next step is: local warehouse and remote warehouseThe connection
Alias the remote repository
- We can see the address of the remote repository, so we use this every time we pull (download) code, or upload code
This address is cumbersome and hard to remember, so we will create an alias for this address and use the alias for all future pull uploads.
Git remote add Alias remote addressGit remote add origin http://... Alias the remote address: origin
git remote -v # check remote address alias, if set to do not have it;
Fatal: remote origin already exists. Alias already exists, can be deleted... Reconfigure a/change the name
git remote rm origin # delete remote library associated with Origin
Fatal: Not a git repository (or any of the parent directories)
git init # ok!!
Copy the code
Push native code to the GitHub repository
Push, is equivalent to: the local warehouse and remote warehouse synchronization ~ the first operation can!
Git push alias branch name# Branch to push ~ (generally speaking, different branches in the company do different things!)Git push -u alias branch name-u Specifies the default host
Git push -u origin master
Copy the code
Upload, also need to enter email/password username for verification:After all, remote uploads can be downloaded by many people... Safety first
Download the GitHub repository codeclone/pull
git cloneThe remote addressCreate origin remote address alias and initialize local.git.Git pull alias branch nameCopy the code
Download the GitHub repositoryclone
- The first download is the operation from scratch, using
git clone
The back can be used directly in the original filegit pull
Command to update the file code - Cloned files are not recommended in the main branch
master
Do development inside - 1. Each github remote repository has its own
The remote connection
Clone /pull through the connection - 2. To differentiate, I created one
zhangsan
Folder.Simulation of a user remote download warehouse development ~
Directly in the Zhangsan directoryGit Bash
Perform:Git Clone Remote address
Began to pull the remote warehouse project! (Github has plenty of open source projects to learn from.)It pulls down the entire warehouse:To your own local warehouse, you can do secondary development... You can also use pull to synchronize updates....
Pull the codepull
- If clone code exists locallyThe code in the pull remote Github is not needed
clone
The clone (copy) operation can be usedpull
Update the local file
Git pull Origin branch name# Create a clone alias for the first time!
# is equivalent toGit fetch Origin Branch nameThe remote file will be pulled to the local library instead of being merged with the original local fileGit merge origin/ git merge origin# merger
Copy the code
Modify the filepush
Remote version library githubpush
Developers download a project and re-develop it. Modify the local/remote synchronization code during the upload…
It’s just a push and you need to do the following
- After modification, local must be added to the staging area first
- Commit to the local version library
- Push to a remote repository
- Be sure to
git status
There are no uncommitted filespush
After the local project is associated with the Github project
- AB Clone the warehouse
- A Modification submission:Someone else modified the file and committed it to github.
B or the previous version is not affected!
- B can go through
Pull performs pull updates
Any public repository can be downloaded, but the push can only be modified by the developer invited by the repository owner
Work Changes are submitted to the remote repositorypush
No synchronization under Zhangsan!
zhangsan pull
Synchronize the remote warehouse!
Conflict handling
For example, if I change a file on Github and then change the same place locally, there will be a conflict.
Github Git\ Note: the local code here has been committed to the local repository.
At this point, if the push code is native, it will prompt an error.
So before pushing a push to a remote repository, pull the code from the remote repository
- You can see that there is a conflict in the A.txt file, and then the command line enters
MERGING mode
- At this time, we can open A.txt to resolve the conflict
Then add A.txt to the staging area, commit, then push, and you're done. 👍
Invite others to join the team
Only invited developers can work on the warehousePush modify commit
First, the warehouse creator:
- Step 1: Click
settings
- Step 2: Find
Manage access
And click the - Step 3: Click
Invite a collaborator
- Step 4: Enter the name or email address of the inviter and press Enter to confirm
- Step 5: Click Submit
- Step 6: Copy the invitation link and send it to the invitee (GitHub will send an email to the invitee)
- Step 7: The invitee login in the browser address bar enter the inviter’s URL, click
Accept invitation
The invite operation is complete
SSH Encryption-free login
When operating the push code based on HTTP/HTTPS, it is troublesome to input the user name and password every time. You can use SSH to establish a secure connection between the local and remote, and then submit the code without input the user name and password!
Limitations: SSH can only be set for one account
The steps are as follows:
The following sources:bosses
- Open the Git command and enter CD ~ to go to the current user’s home directory
- Delete the.ssh directory (I deleted the local directory for testing)
rm -rvf .ssh
- Run the command to generate ·.ssh· key directory (note that C is uppercase)
Ssh-keygen -t rsa-c Your github registered email address
- Copy the SSH -… The file
Modify the newly generated public key!
GitHub branch merge!
The Idea of making operation
Idea is just a tool, powerful tool internal integration Github can be directly downloaded/uploaded… It’s important to know about Github… After understanding
Happy New Year!Fun cow! Fun