Convert a local folder to a Git repo
Last updated
Converting a local folder to a Git repository means initializing Git tracking in that folder so Git can:
Track file changes
Record history
Enable version control
Connect the folder to a remote Git repository (optional)
This process does not move files or change their content — it simply adds Git tracking capabilities to the folder.
We convert a folder to a Git repo when:
We are starting a new project that’s not under version control
We want to add Git tracking to an existing codebase
We plan to push the folder to a remote Git server like GitHub or GitLab
1. Open Terminal and Navigate to the Folder
This should be our project directory with files already present.
2. Initialize the Git Repository
This creates a .git folder inside our directory. That hidden folder stores all Git configuration, branches, commits, and metadata.
3. Stage the Files for Commit
This adds all files in the folder to the staging area (i.e., marks them to be included in the next commit).
4. Create the First Commit
This creates the first snapshot of our project.
At this point, our folder is fully Git-tracked locally. It now has commit history and can use all Git features.
If we want to push our local Git repo to a platform like GitHub or GitLab:
5. Add the Remote Repository URL
Replace
originwith a custom name if we want, butoriginis the default and commonly used.
6. Push the Repo to Remote (first push)
If our branch is called
master, replacemainwithmaster.
The -u flag sets the upstream so that future git push and git pull commands automatically know which remote and branch to use.
We can add a .gitignore file before or after git init to exclude files/folders from being tracked.
If we are working with a team, make sure to push to a remote repo so others can access our code.
git init is non-destructive – it won't delete or overwrite our files.
Last updated
cd /path/to/our/foldergit initgit add .git commit -m "Initial commit"git remote add origin https://our-remote-url.com/our-repo.gitgit push -u origin main