DEV Community

Cover image for Git commands
MOULEESHWARAN S
MOULEESHWARAN S

Posted on

Git commands

Initialize a Git repository:

git init
Enter fullscreen mode Exit fullscreen mode
  • Creates a new Git repository in the folder 24MCR070

Add a file to staging area:

     git add 24MCR070.txt
Enter fullscreen mode Exit fullscreen mode
  • Adds 24MCR001.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".

Check Git status:

 git status
Enter fullscreen mode Exit fullscreen mode
  • Shows that 24MCR070.txt has been modified but not staged.

View commit log:

 git log
Enter fullscreen mode Exit fullscreen mode
  • Displays the commit history (one commit at this point).

Add remote GitHub repository:

 git remote add origin https://github.com/Mouleesh28/24MCR070
Enter fullscreen mode Exit fullscreen mode
  • Links the local repository to a remote GitHub repo.

Check current branch:

 git branch
Enter fullscreen mode Exit fullscreen mode
  • Shows the current branch is master.

Rename branch from master to main:

 git branch -M main
Enter fullscreen mode Exit fullscreen mode
  • Renames the current branch to main.

Set Git global config for email and
username:

  git config --global user.email "mouleeshwaranshanmugam@gmail.com"

  git config --global user.name "mouleesh28"
Enter fullscreen mode Exit fullscreen mode

Sets your global Git identity.

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

Image description

Top comments (0)