DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

Day 2 - GIT commands

Creating Git Folder:

Now, let's create a new folder for our project

mkdir Projectname
cd Projectname
Enter fullscreen mode Exit fullscreen mode

mkdir makes a new directory.
cd changes the current working directory.

Clone an Existing Repository:

Copies a remote repository to your local machine.

git clone <repository_url>
Enter fullscreen mode Exit fullscreen mode

This is useful when you want to contribute to an existing project.

Check the Status of Your Repository:

Shows which files have been modified, staged, or untracked.

git status
Enter fullscreen mode Exit fullscreen mode

Always run this before committing to see what’s changed.

Add Files to Staging:

Moves changes from the working directory to the staging area.

git add <file_name>    # Add a specific file
git add .              # Add all changes
Enter fullscreen mode Exit fullscreen mode

Staging means preparing files to be committed.

Commit Changes:

Saves the staged changes permanently in the repository.

git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

The commit message should describe what changes were made.

Check Your Git Configuration:

To verify your Git username and email, run:

git config --global user.name
git config --global user.email
Enter fullscreen mode Exit fullscreen mode

List All Branches:

Shows all available branches in the repository.

git branch
Enter fullscreen mode Exit fullscreen mode

The current branch will have a * next to it.

Create a New Branch:

Creates a new branch without switching to it.

git branch <branch_name>
Enter fullscreen mode Exit fullscreen mode

Branches help in working on different features separately.

Switch to Another Branch:

Moves to an existing branch.

git checkout <branch_name> 
Enter fullscreen mode Exit fullscreen mode

Check Commit History:

Shows a list of all previous commits.

git log
Enter fullscreen mode Exit fullscreen mode

Show Changes in Files:

Compares modified files with the last committed version.

git diff
Enter fullscreen mode Exit fullscreen mode

Top comments (0)