Basic Git Commands
What Is Git and What Is GitHub
Git is a free, open-source, distributed version control system that handles source code changes in software projects of all sizes. Git allows multiple developers to work together on the same project with ease.
How to Use Git Beginner's Step-by-Step Guide
Step 1: Install Git and Create a GitHub Account
- The first thing you need to do is to install Git and create a GitHub account.
- After installing Git on your machine, the next step is to create a free GitHub account.
Step 2: Create a Local Git Repository
- After installing or updating Git, the next step is to create a local Git repository. Our article explains in detail what a Git repository is and how to create one.
1.Open a Git Bash terminal and move to the directory where you want to keep the project on your local computer. For example:
cd /d D:\Full-stack-js\Assignments\Project-5
In this example, we changed the directory to Desktop and your project folder.
2.Create a Git repository in the selected folder by running the git init command. The syntax is:
git init
git init [repository-name]
Now you have successfully created a local Git repository. There are a few different ways to use git add, by adding entire directories, specific files, or all unstaged files.
git add
Adds files in the to the staging area for Git
$ git add <file or directory name>
In Practice:
# To add all files not staged:
$ git add .
# To stage a specific file:
$ git add index.html
# To stage an entire directory:
$ git add css
git commit
The changes made to the files to a local repository
# Adding a commit with message
$ git commit -m "Commit message in quotes"
git status
This command returns the current state of the repository.
$ git status
git config
there are many configurations and settings possible. git config is how to assign these settings. Two important settings are user user.name and user.email. These values set what email address and name commits will be from on a local computer. With git config, a --global flag is used to write the settings to all repositories on a computer. Without a --global flag settings will only apply to the current repository that you are currently in.
# Running git config globally
$ git config --global user.email "your@emailaddress.com"
$ git config --global user.name "Your Name"
# Running git config on the current repository settings
$ git config user.email "your@emailaddress.com"
$ git config user.name "Your Name"
git branch
To determine what branch the local repository is on, add a new branch, or delete a branch.
# Create a new branch
$ git branch <branch_name>
# List all remote or local branches
$ git branch -a
# Delete a branch
$ git branch -d <branch_name>
git checkout
To start working in a different branch, use git checkout to switch branches.
# Checkout an existing branch
$ git checkout <branch_name>
# Checkout and create a new branch with that name
$ git checkout -b <new_branch>
git merge
git merge combines the changes from one branch to another branch.
# Merge changes into current branch
$ git merge <branch_name>
git clone
To create a local working copy of an existing remote repository, use git clone to copy and download the repository to a computer. Cloning is the equivalent of git init.
$ git clone <remote_URL>
git pull
To get the latest version of a repository run git pull. This pulls the changes from the remote repository to the local computer.
$ git pull <branch_name> <remote_URL/remote_name>
git push
Sends local commits to the remote repository. git push requires two parameters: the remote repository and the branch that the push is for.
$ git push <remote_URL/remote_name> <branch>
# Push all local branches to remote repository
$ git push —all
Thanks for reading
For more details read full documentation about git hub
Subscribe to my newsletter
Read articles from VINOD-KUMAR-M directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
VINOD-KUMAR-M
VINOD-KUMAR-M
I am a Professional Employee at QMS IRCA-Lead Auditor (ISO 9001), IMS (ISO 9001, ISO 14001 & ISO 45001) and LMS (ISO/IEC 17025) Internal Auditor in Non-IT but my passion is learn-code and write code now I am looking forward to collaborating any open source at web development IT sector. I am multi-talented person like a Photoshop editor, computer software/hardware trouble-shooter, I am a fast learner and I always think positive, my ideas are unique and team motivator also you can trust my smart work and I truly Honest person.