DEV Community

Vaishnavi D
Vaishnavi D

Posted on

Basic Git Commands

git init

Initializes a new Git repository in your project directory. This sets up all necessary files and tracking to start version control.

    git init
Enter fullscreen mode Exit fullscreen mode

git add

Adds changes in your working directory to the staging area. You can specify individual files or use . to add all changes.

            git add filename    
            git add .
Enter fullscreen mode Exit fullscreen mode

git commit

Records the staged changes to the local repository with a message describing what was changed.

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

git push

Uploads your local repository content to a remote repository like GitHub.

    git push origin main      
Enter fullscreen mode Exit fullscreen mode

git status

Displays the state of the working directory and staging area. It shows which changes are staged, unstaged, or untracked.

    git status
Enter fullscreen mode Exit fullscreen mode

git log

Shows the commit history for the repository, including commit IDs, messages, authors, and timestamps.

    git log
Enter fullscreen mode Exit fullscreen mode

git branch

Lists all the branches in your repository. The * indicates the current branch.
git branch # List branches

git branch -M

Renames the current branch. Often used to rename master to main.

    git branch -M main        # Renames current branch to 'main'
Enter fullscreen mode Exit fullscreen mode

git config user.name

Sets the username for Git commits. This is usually done globally.

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

git config user.email

Sets the email address for Git commits. This should match your GitHub/GitLab account.

    git config --global user.email "you@example.com"
Enter fullscreen mode Exit fullscreen mode

git remote add origin

Connects your local repository to a remote one. Replace with your actual repository URL.

    git remote add origin https://github.com/username/repository.git
Enter fullscreen mode Exit fullscreen mode




SCREENSHORTS:

Image description

Image description

Image description

Top comments (0)