Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect local folder to Git repository and start making changes on branches?

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.

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?

like image 462
codr Avatar asked Mar 21 '16 13:03

codr


People also ask

How do I turn an existing folder into a git repository?

git init Existing Folder For an existing project to become a Git repository, navigate into the targeted root directory. Then, run git init . Or, you can create a new repository in a directory in your current path. Use git init <directory> and specify which directory to turn into a Git repository.


1 Answers

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 

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


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> 

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> 

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


You can find a good beginners guide to Git here.

like image 168
Harmelodic Avatar answered Sep 23 '22 06:09

Harmelodic