简体   繁体   中英

GitHub setup repository

I did a interview test this week and the test said something like:

Initialize /var/save/my-repo directory as git repository and set the local repository as the remote repository called origin. Perform the following set of actions:

  • Check out the master branch;
  • Create a commit message "my first commit" without quotes;
  • Push the changes to master branch;

I initialized the my-repo folder as a Git repository, but I didn't understand the part of "set the local repository as the remote repository called origin".

Could anyone explain me or tell me how to achieve it?

This is how you do that:

Initialize the local directory as a Git repository.

git init

Add the files in your new local repository. This stages them for the first commit.

git add .

Commit the files that you've staged in your local repository.

git commit -m "my first commit"

At the top of your GitHub repository's Quick Setup page, copy the remote repository URL.

In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

git remote add origin remote repository URL

git remote -v

OR If you are going to create a new repository then use

git remote add origin git@github.com:User/UserRepo.git

Push the changes in your local repository to GitHub.

git push origin master

I got the same question for interview. How to set local repository as the remote repository called origin? Please help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM