Git for software engineers / developer

Hello every one, in this artical we are going to learn about git:

  • What it git ?
  • Git most usefull command

Git is a very powerful version controlling tool which helps us manage our code and collaborate over the cloud. It helps us to track our input in a project in file level even in line level.

Git commands:
init: this command is use to initialize git in any project.

git init

add: this command is used to add current changes to commit.

git add filepath 
git add . //this is used to add all files to current commit

commit: this command is used to commit current added file.

git commit -m "any msg"

push: push is use to upload local changes to remote server/repository.

git push origin branchname

ex: git push origin main

status: git status shows changes in current branch. changes are represented as:

  • red- if there is any conflict in files then it shows in red color
  • green- if there is any local changes in current file then it shows in green color
  • cyan- if any new file is added then it shows in cyan
  • yellow- when file is added to local commit then it shows in yellow
git status

branch: this command is use to display git branch list.

git branch
git branch -a //this is use to display all branches including remote and local.

checkout: this command is primarily use to switch between branches and we can use to create a new branch also we can reset current changes of files.

git checkout branchName //to switch in specific branch
git checkout -b newBranchName //to create new branch from current branch
git checkout filePath //reset to previous commit

stash: this command discard current changes from current branch and save in git history.

git stash //discard current changes
git stash pop //applies the previous changes
git stash pop commitId //this applies specific changes

merge: This command is use to merge 2 branch.

git merge branchName