Home > Web Front-end > JS Tutorial > body text

How to upload local projects to Github using Git

一个新手
Release: 2017-09-20 10:14:00
Original
1659 people have browsed it

I registered Github a long time ago, but I have always been confused and unskilled in using it. Until I finished the task of Baidu Front-end Technology Academy yesterday and wanted to host the code on Github, I found that I was so stupid about the operation of Git, so I decided to learn Git well today so that I can use Github better in the future. , mainly through Git tutorials - Liao Xuefeng's official website to learn. For the brief steps, you can directly look at the final summary.

I won’t talk about the installation of Git.

Step 1: We need to create a local repository (actually a folder).

You can right-click to create a new folder, or you can right-click to open the Git bash command line window to create it through commands.

Now I create a new TEST folder on the desktop through the command line (you can also create this folder anywhere else), and enter this folder

                                                                                                                                                                                                     through the command git init

Make this folder manageable by Git

Warehouse

At this time you will find that there is an additional .git folder in TEST, which is used by Git to track and manage the repository. If you can't see it, it's because it is a hidden file by default, then you need to set it up to make the hidden files visible.

                                       

##             Step 3: At this time you can paste your project into this local Git repository (after pasting, you can

git status

to check your current status), then add the project to the warehouse through git add
(or

git add .

to add all files in the directory to the warehouse, note that the dots are separated by spaces). In this process, you can actually always use git status to view your current status.

   

                                                                                            ’ ’ s to         ‐   ‐ ‐ ‐ ‐

#                      

                                                                                                        git add .Add all the projects just copied to the warehouse.

       

                                                                  ’ ’s ’ s to git commit

                through out ’’s out through out’s ’ ‐ ‐ ‐‐‐‐ ‐ ‐ to storehouse.

               

          -m

The quotation marks behind are the annotations submitted this time. This does not need to be written, but it is best to write it. , otherwise an error will be reported, please Google for details.

Okay, the work on our local Git warehouse is done, now it’s time to connect to the remote warehouse (that is, connect to Github)

Since the local Git warehouse and Github The transmission between warehouses is encrypted through SSH, so you need to set it up when connecting: Step 5: Create SSH KEY. First check if there is a .ssh directory in the user directory of your C drive. If so, check if there are two files

id_rsa

and id_rsa.pub. If so, jump to the next step. One step, if not, create

   $ ssh-keygen -t rsa -C "youremail@example.com"
Copy after login
through the following command and then press Enter all the way. At this time you will find the two files id_rsa and

id_rsa.pub

in the .ssh directory under the user

      第六步:登录Github,找到右上角的图标,打开点进里面的Settings,再选中里面的SSH and GPG KEYS,点击右上角的New SSH key,然后Title里面随便填,再把刚才id_rsa.pub里面的内容复制到Title下面的Key内容框里面,最后点击Add SSH key,这样就完成了SSH Key的加密。具体步骤也可看下面:

       


       

    

        第七步:在Github上创建一个Git仓库。

     你可以直接点New repository来创建,比如我创建了一个TEST2的仓库(因为我里面已经有了一个test的仓库,所以不能再创建TEST仓库)。

   

        第八步:在Github上创建好Git仓库之后我们就可以和本地仓库进行关联了,根据创建好的Git仓库页面的提示,可以在本地TEST仓库的命令行输入:


$ git remote add origin https://github.com/guyibang/TEST2.git
Copy after login

        


        注意origin后面加的是你Github上创建好的仓库的地址。

        

      第九步:关联好之后我们就可以把本地库的所有内容推送到远程仓库(也就是Github)上了,通过:

$ git push -u origin master
Copy after login

       由于新建的远程仓库是空的,所以要加上-u这个参数,等远程仓库里面有了内容之后,下次再从本地库上传内容的时候只需下面这样就可以了:

$ git push origin master
Copy after login

        上传项目的过程可能需要等一段时间,完成之后是这样的:

        

        这时候你再重新刷新你的Github页面进入刚才新建的那个仓库里面就会发现项目已经成功上传了:

      

        至此就完成了将本地项目上传到Github的整个过程。

      另外,这里有个坑需要注意一下,就是在上面第七步创建远程仓库的时候,如果你勾选了Initialize this repository with a README(就是创建仓库的时候自动给你创建一个README文件),那么到了第九步你将本地仓库内容推送到远程仓库的时候就会报一个failed to push some refs to https://github.com/guyibang/TEST2.git的错。

      

      这是由于你新创建的那个仓库里面的README文件不在本地仓库目录中,这时我们可以通过以下命令先将内容合并以下:

$ git pull --rebase origin master
Copy after login

       

       这时你再push就能成功了。

     总结:其实只需要进行下面几步就能把本地项目上传到Github

     1、在本地创建一个版本库(即文件夹),通过git init把它变成Git仓库;

2. Copy the project to this folder, and then add the project to the warehouse through git add .;

3. Then pass git commit -m "Comment content" Submit the project to the warehouse;

4. After setting the SSH key on Github, create a new remote warehouse and pass git remote add origin https://github.com/guyibang/TEST2.gitAssociate the local warehouse and the remote warehouse;

5. Finally passgit push -u origin master Push the project of the local warehouse to the remote warehouse (that is, Github); (If a README file is automatically created when creating a new remote warehouse, an error will be reported. See the solution above).

This is just a summary of some basic operations for uploading projects with Git. If you want to use Git better, you need further learning.

The above is the detailed content of How to upload local projects to Github using Git. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!