Git online version and git online version
Introduction:
I have studied the Git standalone version (individual combat). Today I want to study the Git online version (team collaboration )!
GitHub is an open-source code hosting platform. You can share your code on this platform, so that everyone can participate in development or use it. (You can also build your own Git repository. Related Products: gitlab and coding.net)
I. GitHub (use open-source code to host a repository)
1, create GitHub account: https://github.com/
# After creating a user, click "Settings"> "Emails" in the upper right corner to verify the email address. (We recommend that you do not write Netease's email address, for example, 163/126. Otherwise, you will crash, the verification email sent from github is not received)
2. Open Sehll/git Shell to generate the public key and private key (Linux/Windows)
Shell> ssh-keygen-t rsa-C "wangxiaoqiangs@foxmail.com" # All default carriage return
3. log onto GitHub and click Settings-> SSH keys-> Add an SSH key (with the key, you can prove that you are yours ~ , You can add multiple keys)
Enter Title (any)
Enter the Public Key (Content in id_rsa.pub)
-> Add key
4. In this way, you have settled on GitHub. The content on GitHub is published by default and readable by others.
# Github: https://github.com/wangxiaoqiangs
5. log onto GitHub and click '+' in the upper right corner-> New Repository to create a remote Repository
Repository name: MyTest # Repository name
Description (optional): # repository Description
Public: You can only select this option.
> Create repository
# Now you can see a created empty warehouse with a prompt on it to perform this operation!
2. Interaction with remote warehouses
1. git Configuration
shell > git config --global user.name 'wangxiaoqiangs'shell > git config --global user.email 'wangxiaoqiangs@foxmail.com'shell > git config --global color.ui true
2. Create a local database
Shell> mkdir-p/git/MyTestshell> git init # initialize the git repository Initialized empty Git repository in/git/MyTest /. git/shell> echo "This is a test repository"> README. md # generate a test file and submit it to the local database shell> git add README. mdshell> git commit README. md-m'first commit'
3. Associate remote warehouses and push local warehouses
Shell> git remote add origin git@github.com: wangxiaoqiangs/MyTest. git # local repository associated with remote repository shell> git push-u origin master # push local repository to remote repository. Add the-u parameter Counting objects: 3, done to the first push. writing objects: 100% (3/3), 237 bytes, done. total 3 (delta 0), reused 0 (delta 0) To git@github.com: wangxiaoqiangs/MyTest. git * [new branch] master-> masterBranch master set up to track remote branch master from origin.
# Now go to GitHub and you will see the README. md file in the MyTest repository.
Note: The following prompt appears during the first execution, which is normal.
The authenticity of host' github. com (192.30.252.128) 'Can't be established. RSA key fingerprint is 16: 27: ac: a5: 76: 28: 2d: 36: 63: 1b: 56: 4d: eb: df: a6: 48.Are you sure you want to continue connecting (yes/no )? YesWarning: Permanently added 'github. com, 192.30.252.128 '(RSA) to the list of known hosts. shell> cp/script/20150902/Student_management_system.py. # copy a file to the local repository and submit shell> git add repository> git commit Student_management_system.py-m 'second submission' [master a946cf0] Second submission1 files changed, 124 insertions (+ ), 0 deletions (-) create mode 100644 Student_management_system.pyshell> git remote origin master # push the latest changes to the remote Warning: Permanently added the RSA host key for IP address '2017. 30.252.129 'to the list of known hosts. counting objects: 4, done. compressing objects: 100% (3/3), done. writing objects: 100% (3/3), 1.33 KiB, done. total 3 (delta 0), reused 0 (delta 0) To git@github.com: wangxiaoqiangs/MyTest. git5fdb1c4 .. a946cf0 master-> master
# Now a new file is available in the remote repository ~
4. Clone from remote Repository
# Log onto GitHub to create a remote Repository
Repository name: GithubTest # Repository name
Description (optional): # repository Description
Public: You can only select this option.
Initialize this repository with a README: select this check box to automatically generate README. md
> Create repository
# Create a remote repository and generate the README. md File
Shell> cd/git/shell> git clone git@github.com: wangxiaoqiangs/GithubTest. git # clone a copy from the remote repository to the local Initialized empty Git repository in/git/GithubTest /. git/remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 sorting ing objects: 100% (3/3), done. shell> cd GithubTest/; ls # README. the md file has been cloned to the local README. mdshell> modify README. md file, add a line of Local changeshell> git add README. mdshell> git commit README. md-m'first submission' shell> git push origin master
# Push changes to a remote Repository
Iii. Branch Management
Shell> git clone git@github.com: wangxiaoqiangs/MyTest. git # clone a remote database to local shell> git branch # view local branches * mastershell> git checkout-B dev # create and switch branches (git branch dev # create branch git checkout dev # Switch Branch) switched to a new branch 'dev' shell> git branch # view the branch again, * represents the current Branch * devmastershell> echo 'this is a testing'> T.txt # creates a test file, and submit shell> git add T.txt shell> git commit T.txt-m' dev commit '[dev 59b4093] dev commit1 files changed, 1 insertions (+), 0 deletions (-) create mode 100644 T.txt shell> git checkout master # switch back to the master branch Switched to branch 'master' shell> git branch # You can see that the current branch is a master, the T.txt file created in the dev branch is not visible, because the dev * mastershell> git merge dev # branch has not been merged into the current branch, that is, the master) branch Updating a946cf0..59b4093Fast-forwardT.txt | 1 + 1 files changed, 1 insertions (+), 0 deletions (-) create mode 100644 T.txt shell> git branch-d dev # Delete dev branch, you can also disable Deleted branch dev (was 59b4093 ). shell> git branch # Only the master branch is left in the repository again * mastershell> git push origin master # push the changes to the remote repository Counting objects: 4, done. compressing objects: 100% (2/2), done. writing objects: 100% (3/3), 279 bytes, done. total 3 (delta 1), reused 0 (delta 0) To git@github.com: wangxiaoqiangs/MyTest. gita946cf0 .. 59b4093 master-> master
# If the merge branch conflicts, manually edit the file and submit the file again (git add File.txt, git commit-m 'commit ')
# If there are other branch modification files, do not modify the files in the master Branch before merging; otherwise, the merge conflicts
# View merged logs: git log -- graph -- pretty = oneline -- abbrev-commit
# When merging branches: git merge -- no-ff-m "merge with no-ff" dev. with the -- no-ff parameter, you can check the merged logs after deleting the branches.