GitHub personal notes

Source: Internet
Author: User
Tags git commands

GitHub is a distributed code management tool. It was initially developed by Linus to manage Linux open source code. However, it has gradually become the most popular distributed version management tool, and many people use it to manage their own source code.

1. Register a GitHub account and create a repository:
Register a GitHub account and create a repository (repository). You can only create public repositories for free.

 

2. Install the msysgit client:
: Http://msysgit.github.io/
It is strongly not recommended to use a graphical interface, because I have not used it for a long time. Write down several simple commands to upload code under Unix-like command lines.

3. Configure git:
Create an SSH key locally:
$ Ssh-keygen-t rsa-c "[email protected]"
Change [email protected] to your email address, and then you will be asked to confirm the path and enter the password. We will use the default one-way carriage return. If it succeeds ~ /, Generate the. Ssh folder, go in, open id_rsa.pub, and copy the key.
Go back to GitHub, go to account settings, select SSH keys on the left, add SSH key, enter the title, and paste the key. In git bash, enter:
$ Ssh-T [email protected]
If this is the first time, you will be prompted whether to continue. If you enter yes, you will see: You 've successfully authenticated, but GitHub does not provide shell access. This indicates that GitHub has been successfully connected.
Next, we need to upload the local repository to GitHub. Before that, we need to set username and email, because every time GitHub commit records them.
$ Git config -- global user. Name "your name"
$ Git config -- global user. Email "[email protected]"
Go to the repository to be uploaded, right-click git bash, and add the remote address:
$ Git remote add origin [email protected]: yourname/yourrepo. Git
Yourname and yourrepo indicate your GitHub user name and the newly created repository. git: Open config. Here, there will be an additional remote "origin" content, which is the remote address just added. You can also directly modify config to configure the remote address.

4. Upload and submit the Code:
In git bash, go to the folder of the project to be uploaded;

Run $ git Init;
Generate the. Git directory used to record version database history

Run $ git touch readme;
Add descriptive files.

Execute $ git Add .;
Add the information of the file to be submitted to the index database. It indicates all files. You can specify only the files to be uploaded.

Run $ git commit-m'osasystem ';
Add commit information to describe the main information of a project.

Run $ git remote add origin1 [email protected]: 55466867/oasystem. Git;
Establish a remote connection with GitHub. 55466867 is the name of my GitHub account, and oasystem is the name of the previously created repository.

Execute $ git push-u origin master;
Upload files to GitHub.

5. Download others' project code:
Take a user with username as an example. Run the clone command to download the project named test.
$ Gitclone [email protected]: username/test. Git

Note:
If the file name contains spaces, You can enclose them in single quotes.
Use the following command to configure the encoding format:
$ Git config -- Global i18n. commitencoding UTF-8

Appendix (Common git commands, not original found on the Internet ):

Git status check status
Git log to view your commit log
Git commit-A submits all changes to the current Repos
Git commit-M add commit Information

1) remote warehouse commands
Check out Repository: $ git clone git: // github.com/jquery/jquery.git
View remote Repository: $ git remote-V
Add a remote Repository: $ git remote add [name] [url]
Delete a remote Repository: $ git remote RM [name]
Pull remote Repository: $ git pull [remotename] [localbranchname]
Push remote Repository: $ git push [remotename] [localbranchname]

2) branch operation commands
View local branches: $ git Branch
View remote branches: $ git branch-R
Create a local branch: $ git branch [name] ---- note that the new branch will not automatically switch to the current branch after it is created
Switch branch: $ git checkout [name]
Create a new branch and immediately switch to the new branch: $ git checkout-B [name]
Delete branch: $ git branch-d [name] -----D option can only delete the branches that have already joined the merge operation. To force delete a branch, use the-D option.
Merge branch: $ git merge [name] ---- merge the branch named [name] with the current Branch
Create a remote Branch (push local branch to remote): $ git push origin [name]
Delete remote branch: $ git push origin: heads/[name]

3) version (TAG) related commands
View version: $ git tag
Create version: $ git tag [name]
Delete version: $ git tag-d [name]
View the remote version: $ git tag-R
Create a remote version (push local version to remote version): $ git push origin [name]
Delete remote version: $ git push origin: refs/tags/[name]

4) submodule related operation commands
Add sub-module: $ git submodule add [url] [path]
Initialize the sub-module: $ git submodule init ---- run the command only once when the repository is checked out for the first time
Update sub-module: $ git submodule Update-run each update or switch Branch
Delete a sub-module: $ git Rm -- cached [path]

5) Ignore some files and folders and do not submit them.
Create a file named ". gitignore" in the root directory of the repository and write the folder name or file that is not required. Each element occupies one row, as shown in:

Target
Bin
*. DB

 

GitHub personal notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.