如何将本地文件夹连接到 Git 存储库并开始对分支进行更改? [英] How to connect local folder to Git repository and start making changes on branches?

查看:10
本文介绍了如何将本地文件夹连接到 Git 存储库并开始对分支进行更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是源代码管理新手;过去,我手动备份文件副本并对克隆进行更改,然后在调试后手动将更改传输到主文件.我意识到这类似于分支如何使用 Git 存储库,但是我从未使用过.

I'm new to source control; in the past, I've manually backed up copies of files and made changes on clones then transferred changes manually to master files once debugged. I realize this is similar to how branches work with Git repositories, however I've never used one.

我下载了 Git 并在 GitLab 上注册了一个帐户,然后开始了一个新项目.我的网站托管在本地服务器上,我的文件保存在本地.如何将这些文件连接到 Git 存储库并继续使用分支进行开发?

I downloaded Git and made an account on GitLab, and started a new project. My site is hosted on a local server and my files are saved locally. How do I connect these files to a Git repository and continue developing with branches?

推荐答案

要将项目注册为本地 Git 存储库,您需要做的第一件事是在 项目根目录 执行以下命令:

To register a project as a local Git repository the first thing you need to do is perform the following command at your project root:

git init

这将在您的项目根目录创建一个 .git 文件夹,并允许您在该存储库中开始使用 Git.

This will create a .git folder at your project root and will allow you to start using Git in that repository.

如果您想将本地 Git 存储库推送"到远程 Git 服务器(在您的情况下,推送到 GitLab),您需要先执行以下命令:

If you want to "push" your local Git repository to a remote Git server (in your case, to GitLab), you'll need to perform the following command first:

git remote add origin <Repository_Location>

您可以随意调用 origin,但 origin 是 Git 远程存储库的标准名称. 是远程存储库的 URL.例如,如果我有一个名为 MyNewProject 的新项目想要推送到 GitLab,我会执行:

You can call origin whatever you like, really, but origin is the standard name for Git remote repositories. <Repository_Location> is the URL to your remote repository. For example, if I had a new project called MyNewProject that I wanted to push to GitLab, I'd perform:

git remote add origin https://gitlab.com/Harmelodic/MyNewProject.git

然后,您可以使用以下命令将更改从本地计算机推送"到远程仓库:

You can then "push" your changes from your local machine to your remote repo using the following command:

git push origin <branch_name>

其中分支名称是您要推送的分支的名称,例如master.

where branch name is the name of the branch you want to push, e.g. master.

您可以在此处找到优秀的 Git 初学者指南.

这篇关于如何将本地文件夹连接到 Git 存储库并开始对分支进行更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆