GIT Essential Commands

Sep 02, 2019 by - Category - Devops

Introduction & Working Directory :

Basically GIT is a remote repository which stored in a server and local repositories on the local system of each and every developer. We can say in the easy words the code is not just stored in a central server, but the full copy of code is available on the developer’s system.

Working Directory –

The working directory is the root directory where you have entire code that you want to manage with git.

Commit :

commit is set a message about the changes you have done in working directory, and it’s kept track of using a unique alphanumeric character. The commit also saves a revision of the code and you can revert the code to any version anytime.

Index :

The index is used as a staging area between your working branch to your repository. You can use index to build a set of code / changes into your file and further track them and commit all of them into the master.

Branch :

branch is the basic routine of your every day development. Git Branch always had a pointer or snapshot of your current changes. When you will create a new feature or fixing your bugs, you must need to create a new branch to push your code in the master branch.

Git Commands :

  • .git
  • HEAD / ( Is a ref to the last commit in the currently checked out branch )
  • Config / ( Contains all configurations preferences )
  • Descriptions / ( Descriptions about your project )
  • index  / ( Is used as staging area between working directory and repo )
  • Logs / ( keeps records to change that are made in ref )
  • Objects / ( All data are stored here: commits, trees and tags )
  • Hooks / ( Shell scripts that are invoked after executing a command )
  • Refs / ( Holds your local branch remote branch and tags )
  • Init ( Create a local repo )
  • Clone ( Checkout the repo and create a local copy of it )
  • Status ( To see the status of your file ( modified, added, remote ) )
  • Add ( add files to your staging area )
  • Checkout ( This command is used to switching branches  )
  • Commit ( Commit a stage file ) 
  • Log ( Get the history of your commit )
  • Remote ( Shows the remote repo name by default it is Origin )
  • Fetch ( Download object and refs from another repo)
  • Push ( Push your changes ( commits ) into your branch )
  • Pull ( Update remote repo and sink your local repo with master )

 

Execute Git Commands :

Set User Identity :
$ git config –global user.name “John Doe”
$ git config –global user.email johndoe@example.com

Creating a repository :
$ git init

Cloning repository :
$ GIT CLONE HTTPS://GITHUB.COM/DBRGN/FAHRPLAN

Git Commands :

Add a new file  - $ git add <File Path>
Remove a new file - $ git rm <File Path>
Commit file or code changes from local to stage - $ git commit -m 'Meaning Full Commit Message'
Commit message change after commit and before push into the branch - $ git commit --amend
Show logs / history of commits - $ git log
Show commit - $ git show
Show code changes in file - $ git diff <File Path>

How to Create Branch in Git ?

$ git checkout master
$ git reset --hard origin/master ( Git Head set on the updated last commit )
$ git pull origin master
$ git checkout -b ext_discriptive_name_of_the_card
$ git push --set-upstream origin ext_discriptive_name_of_the_card
Switch to a new branch - $ git checkout demo_new_branch
Delete branch - $ git branch -d demo_new_branch

Code Merge & Resolve Conflicts –

git checkout <master Branch>
git reset --hard HEAD^
git pull origin <master brach>
git checkout <Into your working branch>
git merge --no-ff origin/master
git status
git diff < File Name >
git add < File Name  >
( For Checking Auto Generated Commit Message )
git merge --continue
git commit 

( Without commit message “NOTE: While resolving conflict we will not use git commit -m  “Commit Message”

Standard resolved conflict message like –
** Merging remote-tracking branch ‘origin/master’ into < Branch Name > **

git push origin < Branch Name >

These are the basic commands to understand GIT, we will update some more tutorials and advanced GIT practices into our new blog. Please use this on your daily routine to avoid the basic mistakes on code deployment.

Leave a Reply

Your email address will not be published. Required fields are marked *

one × five =