DEV Community

Shreeprabha bhat
Shreeprabha bhat

Posted on

BEGINNERS COMMAND - GIT

GIT

GIT is a version control system that is designed to handle small to large projects with speed and efficiency. It allows multiple people to work on same project simultaneously without effecting other's code.
GIT is most common skill that recruiters expect in everyone's resume. There are some of the basic commands that must be known to everyone while working with git or attending any technical interview.

MUST KNOW GIT COMMANDS

These commands are used to setup git in your system. Using the commands below one can access the git synchronized with the mail ID.

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

This command is used initialize a repository in your git. Once the repository is initialized other actions like commit, push or pull can be performed over these repository.

git init
Enter fullscreen mode Exit fullscreen mode

Below command is used to clone an existing repository into your repository.

git clone <repository_url>
Enter fullscreen mode Exit fullscreen mode

The command below is used to get the status of repository.

git status
Enter fullscreen mode Exit fullscreen mode

Stage the changes for commit.

git add <file_name> 
# Command stages the changes in that particular file
git add .
#Command stages the entire changes.
Enter fullscreen mode Exit fullscreen mode

Commit changes to the repository

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

View the history of commits in the repositiory

git log
Enter fullscreen mode Exit fullscreen mode

Creating a new branch.

git branch <branch_name>
Enter fullscreen mode Exit fullscreen mode

Switch to a new branch

git checkout <branch_name>
Enter fullscreen mode Exit fullscreen mode

Create and switch to a new branch

git checkout -b <branch_name>
Enter fullscreen mode Exit fullscreen mode

Merge a branch to the new branch

git merge <branch_name>
Enter fullscreen mode Exit fullscreen mode

Know which branch you are working in.

git branch
Enter fullscreen mode Exit fullscreen mode

Add a repository to the remote repositiory

git remote add origin <repository_url>
Enter fullscreen mode Exit fullscreen mode

Fetch changes from the remote repository

git fetch
Enter fullscreen mode Exit fullscreen mode

Push changes to the remote repositiory

git push origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

Pull changes from the remote repository

git pull
Enter fullscreen mode Exit fullscreen mode

List remote repositories

git remote -v
Enter fullscreen mode Exit fullscreen mode

Stash the changes when your are not ready to commit them.

git stash
Enter fullscreen mode Exit fullscreen mode

Apply the stashes to the desired branch

git stash apply
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
vidyarathna profile image
Vidyarathna Bhat

Great post, Shreeprabha! This is a concise and helpful guide for beginners to get started with Git. It covers all the essential commands needed for basic version control tasks. Looking forward to more of your content!