简体   繁体   English

如何将本地仓库添加到分支

[英]How to add local repo to the branch

没有本地回购 :-(

I'm new in GitHub, as you can see in the picture I have no local repo I only have branch (main) without local repo.. How can I add one so that I can push my local repo to the remote repo?我是 GitHub 的新手,如图所示,我没有本地存储库,我只有分支(主),没有本地存储库。如何添加一个以便将本地存储库推送到远程存储库?

Thank you..谢谢..

You have to follow few steps.你必须遵循几个步骤。 if you don't have the local repo configured.如果您没有配置本地存储库。 Do this做这个

1. Initialize the git for the repostory 1.为repostory初始化git

git init

2. Add your repo origin to git 2. 将你的 repo origin 添加到 git

git remote add origin <YOUR REPO PATH/URL>

Example is below示例如下

git remote add origin https://github.com/github/docs.git

By default it will be in the master/main branch.默认情况下,它将位于 master/main 分支中。

If you have any local changes.如果您有任何本地更改。

3. First stage them and run these commands 3. 首先暂存它们并运行这些命令

git add .
git commit -m "Your message"
git pull

git pull is if you have any changes in the repo but you don't have them, to merge them locally. git pull是如果您在 repo 中有任何更改但您没有更改,请在本地合并它们。

4. Now push the code to the repo. 4. 现在将代码推送到 repo。 git push or git推或

git push origin YOUR-BRANCH-NAME

Example例子

git push origin master or git push origin main

Now when you're pushing the code for the very first time.现在,当您第一次推送代码时。 Then, follow step 1 and step 2 and write these commands然后,按照步骤 1步骤 2编写这些命令

git add .
git commit -m "Your Message"
git push origin Your-Branch-Name

Example例子

git push origin master

You can also find the help here Git Help commands您还可以在此处找到帮助Git 帮助命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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