DEV Community

Cover image for Create a Local Git Repository
Kaviyarasu S
Kaviyarasu S

Posted on • Edited on

Create a Local Git Repository

Initialize a Git repository:

git init
Enter fullscreen mode Exit fullscreen mode

Creates a new Git repository in the folder 24MCR054.

Image description

Add a file to staging area:

git add 24MCR054.txt
Enter fullscreen mode Exit fullscreen mode

Image description

Adds 24MCR054.txt to the staging area.

Commit the file:

git commit -m "Added Personal Details"
Enter fullscreen mode Exit fullscreen mode

Creates a commit with the message "Added Personal Details".

Image description

Check Git status:

 git status
Enter fullscreen mode Exit fullscreen mode

Shows that 24MCR054.txt has been modified but not staged.

Image description

View commit log:

 git log
Enter fullscreen mode Exit fullscreen mode

Displays the commit history (one commit at this point).

Image description

Add remote GitHub repository:

 git remote add origin https://github.com/Kavi-26/24MCR054.git
Enter fullscreen mode Exit fullscreen mode

Links the local repository to a remote GitHub repo.

Image description

Check current branch:

 git branch
Enter fullscreen mode Exit fullscreen mode

Shows the current branch is main.

Image description

Rename branch from master to main:

 git branch -M main
Enter fullscreen mode Exit fullscreen mode

Renames the current branch to main.

Image description

Set Git global config for email:

git config --global user.email "26kaviyarasu2002@gmail.com"
Enter fullscreen mode Exit fullscreen mode

Sets your global Git identity.

Image description

Push code to remote repo for the first time:

 git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Pushes the main branch to GitHub and sets upstream tracking.

Image description

Then , Again We will Modify or add new file means we need to follow the same steps, like

git add .
git commit -m “message”
git push origin main
Enter fullscreen mode Exit fullscreen mode

Image description

Github Repository:

Github link: https://github.com/Kavi-26/24MCR054

Image description

Image description

Top comments (0)