Push your local branch to someone else's remote repository

Source: Internet
Author: User
Tags commit

About pushing a local branch to a remote branch, although it has been done before, but not thoroughly understood, the actual process of understanding the operation is really understood by pushing the part of your project to the teammate's GitHub today. The process refers to http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 and searches on the web for places that you don't understand. It takes a long time to figure out a small problem for people like me who are slow to learn things, so make a quick note of what you understand today.

To push a branch of a local repository to a remote repository, it is divided into the following steps:

1. Create a version library

$ mkdir Lab
$ CD Lab
Where lab is the name of the library you created.

And then enter

Git init
When this step is complete, open the lab folder and discover that it is empty because we have not yet added files to it.

Paste the file you want to add to the lab folder and do the following

git Add.
The file has been added to the library at this time.

Then commit

Git commit-m "First commit"
2. Create a remote repository

If you want to push to your GitHub, sign in to your GitHub account, and in the upper left corner, click Create a new repository, creating a remote repository with the same name as the local repository. If you are pushing to someone else's remote repository, be careful to look at the remote repository name of the other person and be consistent when creating the local repository.

3. Connecting to a remote repository

Once the remote repository is built, you will need to connect to the remote repository locally. Use the following statement to implement the connection

Git remote add origin git@github.com:<span style= "color: #ff0000;" >your Name</span>/lab.git
Where your name needs to write the account name of the GitHub account you want to push to, if you push to your github, fill in your account name, and if you push to GitHub on your teammates, fill in your teammate's account name. Origin is the name of the remote repository and is the default, so do not change it.

4. Push local branch

After the remote library is connected, it is pushed. Using statements

Git push origin <span style= "color: #ff0000;" >branch-name</span>
Push performs a push of the local branch to the remote repository. Where Branch-name is the branch you want to push. If you are pushing master, the statement is
Git push Origin Master
The other same. The first time I was in touch I couldn't figure out if I could just push the master branch, if I had to push another branch to build a new branch on GitHub, and later found that if you were pushing other branches directly, you would automatically create a new branch on GitHub, which is the branch you pushed up. Of course if there is a conflict remember to deal with the conflict.


Well, this is probably the process, I refer to someone else's blog summary of Something, if the wrong place to point out, thank you ~ ~



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.