Creation and association of local git repositories and remote repositories

Source: Internet
Author: User

    • Create a new remote repository (empty)

Create a new remote repository
    • Set the name of the remote repository and create

Set the warehouse name

Remember : If we add the Readme and. Ignore files when we create the remote repository, we need to perform the operation after we have associated the warehouse. pull

    • Create a local folder locally


      To create a folder locally
    • Use terminal to enter the current folder directory

      cd /Users/Sunshine/Documents/大神班/练习/0721/helloTest

      Use terminal to enter this folder
    • Initialize this local folder as a Git manageable repository
      init
      Note: Git will automatically create a unique branch for US master
      We can find a directory in the current directory .git , this directory is git to track the management of the repository, do not manually modify the files in this directory, or change the mess, the Git repository to destroy.

Initializing the Local warehouse
    • Associating a local warehouse with a remote warehouse
      git remote add origin git@github.com:YotrolZ/helloTest.git
      Note: origin This is the name of our remote library, which is the default term for git 也可以改成别的 ;
      [email protected]:YotrolZ/helloTest.gitis the path to our remote repository (we use GitHub here)

Associating a local warehouse with a remote warehouse
    • So that we can start working in a local folder, and here we'll create a main.m file

      • New file

        touch main.m
      • Add the new main.m file to the repository (so git will have 追踪 this file)

        git add main.m
      • Submit the file to the warehouse

        commit -m "新建了一个man.m文件"

Create a new main.m file in the local warehouse
    • Push the contents of the local library to the remote
      push -u origin master
      • Remark: origin : remote warehouse name; master : Branch
      • Note: For the first time push , with -u parameters, Git will associate the local master branch with the remote Master branch, and we will push no longer need to add parameters to our operations -u .

Push to a remote repository
    • We used a browser to access the remote repository and found that there were files in the remote repository mian.m

      A main.m file is also available in the remote repository
    • If one day we have modified the mian.m file (here we add a "Hello World" in the main.m file)

      Modify the Main.m file
    • We can use git status view status

      View status
    • Adding files to the Git repository is actually 文件修改 adding to the暂存区

      git add main.m
    • Commit the changes, in effect, 暂存区 all the content is submitted to 当前分支 .


      Submit Changes
    • View status again
      git status

      View status again
    • Pushes the latest changes to the local current branch to the remote repository on GitHub
      push origin master

      Push the modified MAIN.M file to the remote repository
    • Using the browser to view the remote repository, we see that the local changes have been pushed to the remote repository.

      viewing in the remote repository
Summarize
  • Initialize a local git repository (initialize the local folder to a repository that git can manage)

    init

    Note: The command line terminal needs to be 当前文件目录

  • Add files to the local repository

    git add 文件名
  • Submit file changes to the warehouse

    commit -m "注释"
  • Associate a remote Warehouse

    git remote add origin git@github.com:YotrolZ/helloTest.git
  • Push the latest changes to the remote repository

    push -u origin master
    • Attention:
      1. Each push must be preceded git add 文件名 andgit commit -m "注释"
      2. When the first push is made, we add the -u parameters, and we don't need to add parameters when we push. -u

Creation and association of local git repositories and remote repositories

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.