DEV Community

Cover image for πŸš€ Step-by-Step Git Commands for First-Time Repo Setup (with GitHub)
karthik santhosh
karthik santhosh

Posted on

πŸš€ Step-by-Step Git Commands for First-Time Repo Setup (with GitHub)

1. πŸ“ Initialize a Git repository

git init
Enter fullscreen mode Exit fullscreen mode

Creates a new local Git repository in your current directory (e.g., 24MCR001).


2. βž• Add a file to the staging area

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

Stages 24MCR050.txt to be included in the next commit.


3. βœ… Commit the staged file

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

Creates a commit with a clear message describing the changes.


4. πŸ“‹ Check the Git status

git status
Enter fullscreen mode Exit fullscreen mode

Shows the current status of your working directory and staging area β€” useful to confirm what’s staged or modified.


5. πŸ•“ View commit history

git log
Enter fullscreen mode Exit fullscreen mode

Displays a list of commits, starting with the most recent.


6. 🌐 Link your local repo to GitHub

git remote add origin https://github.com/karthikio/24MCR050.git
Enter fullscreen mode Exit fullscreen mode

Connects your local repository to a remote GitHub repository.


7. 🌿 Check the current branch

git branch
Enter fullscreen mode Exit fullscreen mode

By default, Git creates a branch named master.


8. πŸ”€ Rename branch to main (recommended)

git branch -M main
Enter fullscreen mode Exit fullscreen mode

Renames master to main β€” the new standard for default branches.


9. πŸ‘€ Set your global Git config

git config --global user.email "developer.karthiksanthosh@gmail.com"
git config --global user.name "karthikio"
Enter fullscreen mode Exit fullscreen mode

Sets your identity globally for Git commits.


10. πŸš€ Push your code to GitHub

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

Pushes the main branch to the remote repository and sets the upstream so you can use git push and git pull without arguments next time.


πŸ”„ Updating Files Later

Once you've done the initial setup, any time you modify or add files, follow these steps again:

git add .
git commit -m "Your commit message"
git push origin main
Enter fullscreen mode Exit fullscreen mode

This will stage all changes, commit them with a message, and push to the main branch on GitHub.


Image description
Image description
Image description

Top comments (1)

Collapse
 
developersakthi profile image
Sakthivel R • Edited

nice blog Karthik!