Git use-add local project to remote code library

Source: Internet
Author: User

Recently, I just got started with GIT and found it quite useful. In addition, OSC also provides a free hosting repositorySynchronize the code on your computer to OSC, The results always show various failures. Most of the Solutions for online search are to create a project on [email protected] And then clone it to the local device, I want to push the repository that has been created locally to [email protected. I tried to solve the problem for a long time and shared my approach.

Usage scope: You have created a local repository using the GIT init command locally and want to push the local repository to [email protected. For more information about git installation and usage, see the http://git.oschina.net/progit/ for details on git usage (all my operations are performed on Linux and should be done through msysgit on Windows)

Step 1:Create a local repository for pushing to a distant repository [email protected]

1. Create a local project, studygit, for testing.

# Cd./studygit // enter the root directory of the project

2. Create a local repository for the studygit project, go to the root directory of the studygit project, and perform the following operations under the root directory:

# Git init // at this time, only some initial work is performed according to the directory structure of the studygit project. The file of the studygit project has not been finally submitted to the local repository.

3. Submit the files in the studygit project to the local repository:

# Git add. // Add all files in the directory to the temporary storage area # git commit-a-m "Initial commit" // The studygit project record is saved in the local repository, next, you can push the content in the local repository to the remote repository.

Step 2:Create an SSH connection Public Key for the current user (my root user) and add the public key to the personal [email protected] account for verification when pushing to the remote server.

For more information, see other articles.

Step 3:Add a remote repository for the studygit project and push the code in the Local repository to the remote Repository:

1. Create a studygit project repository on [email protected] and use it as a remote repository. You do not have to call studygit another name;

2. Go to the root directory of studygit and add a remote repository for this project (note that you must enter the directory of the studygit project, not necessarily the root directory. Sub-directories can also be used ):

# Git remote add OSC [email protected]: flan/studygit. git // 1. "OSC" is the alias of the remote warehouse address (not the name of the item on the remote warehouse). The default value is origin.

3. studygit. Git is a remote repository just created on git.oschina.net;

# Git remote-V // you can view the remote repository address connected to the current project.

4. Push the local repository to the remote repository on [email protected:

# Git push-u OSC master // "OSC" is the name of the created remote warehouse, and "master" is the main branch of the Local warehouse (currently only this branch is available, no other branches)

If an error is reported:

To [email protected]:yangzhi/hello.git ! [rejected]        master -> master (fetch first)error: failed to push some refs to ‘[email protected]:yangzhi/hello.git‘hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinhint: to the same ref. You may want to first merge the remote changes (e.g.hint: ‘git pull‘) before pushing again.hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

You can enter:

git push -f 

5. Clone the code locally:

Git clone [email protected]: User Name/project name. Git

Http://guxiaojje.blog.163.com/blog/static/140942291201272110343064/

 

Git use-add local project to remote code library

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.