What is “git remote add …” and “git push origin master”?

前端 未结 6 2048
栀梦
栀梦 2020-12-04 04:11

Quite often, Git and Rails looks like magic... such as in the first chapter of Rails 3 Tutorial book, it talks about Git:

git remote add origin git@github.co         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 05:10

    Have a look at the syntax for adding a remote repo.

    git remote add origin 
    

    Example:

    git remote add origin git@github.com:peter/first_app.git
    

    Let us dissect the command :

    git remote this is used to manage your Central servers for hosting your git repositories.

    May be you are using Github for your central repository stuff. I will give you a example and explain the git remote add origin command

    Suppose I am working with GitHub and BitBucket for the central servers for the git repositories and have created repositories on both the websites for my first-app project.

    Now if I want to push my changes to both these git servers then I will need to tell git how to reach these central repositories. So I will have to add these,

    For GitHub

    git remote add gh_origin https://github.com/user/first-app-git.git
    

    And For BitBucket

    git remote add bb_origin https://user@bitbucket.org/user/first-app-git.git
    

    I have used two variables ( as far it is easy for me to call them variables ) gh_origin ( gh FOR GITHUB ) and bb_origin ( bb for BITBUCKET ) just to explain you we can call origin anything we want.

    Now after making some changes I will have to send(push) all these changes to central repositories so that other users can see these changes. So I call

    Pushing to GitHub

    git push gh_origin master
    

    Pushing to BitBucket

    git push bb_origin master
    

    gh_origin is holding value of https://github.com/user/first-app-git.git and bb_origin is holding value of https://user@bitbucket.org/user/first-app-git.git

    This two variables are making my life easier

    as whenever I need to send my code changes I need to use this words instead of remembering or typing the URL for the same.

    Most of the times you wont see anything except than origin as most of the times you will deal with only one central repository like Github or BitBucket for example.

提交回复
热议问题