Git

Git Basic Development Commands

Git Basic Development Commands

Hello to all, welcome to therichpost.com. In this post, I will tell you Git Basic Development Commands. Git create, Git Revert, Git update, Git Branch, Git Publish and many more git commands. I will tell you Important Git Basic Development Commands, which will useful to all.

Git Config

 Following command is used to configure the author name and email address.

git config --global user.name "Ajay Malhotra"

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

 Git Initialize

 Following command is used to create a new local git repository, also we can initialize git in any of our previous projects.

git init

 Git Clone

 Following command is used to clone a repository.

//local repository: 
git clone /path/to/repository 

//remote server, use: 
git clone https://github.com/project.git

 Git Push

  Following command is used to push all the files to the remote repository.

// Send changes to the branch of your remote repository. 
git push origin master 

// Push the branch to your remote repository, so others can use it:
git push origin <branchname> 

// Push all branches to your remote repository: 
git push --all origin 

// Delete a branch on your remote repository: 
git push origin :<branchname>

 Git Pull

 Following command is used to fetch and merge all the changes on the remote server to your working directory.

// Pull changes from specific branch 
git pull origin <branchname> 

// Pull the current branch from the remote server 
git pull

 Git Status

 Following command is used to show the list of the files you’ve changed and those you still need to add or commit.

git status

 Git Remote

 Following command is used to connect your local repository to the remote server.

// Add the server to be able to push to it: 
git remote add origin <server> 

// List all currently configured remote repositories: 
git remote -v

 Git Checkout

 Following command is used in multiple areas. Such as creating a branch, undo local changes and many more.

// Create a new branch 
git checkout -b <branchname> 

// Switch from one branch to another branch 
git checkout <branchname> 

// You can replace the changes in your working tree with the last content in the head. 
git checkout -- <filename>

 Git Branch

 Following command is used to check the list of branches and delete any of specific branch.

// List all the branches in your repository. 
git branch 

// Delete the feature branch: 
git branch -d <branchname>

 Git Merge

  Following command is used to merge a branch into your active branch.

git merge <branchname>

 Git Diff

 Following command is used to view all the merge conflicts.

git diff

// View the conflict against the base file.
git diff --base <filename>

// Preview changes, before merging
git diff <sourcebranch> <targetbranch>

 Git Stash

When we are working on part of your project. And you face a situation you need to pull the changes from a remote server but an issue is your work is not completely done. In this condition, git stash command is used to store all of our modified tracked files and staged changes into a stack of unfinished changes. We can re-apply at any time.

// Create a new stash
git stash

// Show the list of available stash
git stash list

// Reapply the last stash files to the working area
git stash apply

// If you want to apply one of the older stashes, you can specify it by naming it, like this
git stash apply stash@{n} // n is a stash index, you can get this value when you use git stash list

// If you want to unapply the applied stash
git stash-unapply

 There are some useful commands in this post, if you have any query related to this post, then please do comment below.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

3 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.