DEV Community

rohitreddyk33
rohitreddyk33

Posted on

Every Git command a DevOps Engineer must know(Basic, Advanced)

Basic Git:

  • git init: Initializes an empty git repository
  • git add : Adds the files into staging area
  • git commit : Selects the changes which are staged for the next commit.
  • git commit -a -m ""- commits the changes without the file being undergoing the staging area
  • git remote add origin - adds the pathway from our local git to the remote repo.
  • git remote set-url origin-To change the remote repo to another remote.
  • git remote -v- Displays the pathway of remote repo which the user has set.
  • git config --global user.name "" - configures the username
  • git config --global user.passsword "" - configures the password
  • git config --global --edit - To edit the configured details
  • git status - Shows the status of the files and displays whether the respective files are already staged,committed or yet to stage, commit
  • git log- displays the log of the previous commits
  • git log --oneline - displays the previous commits in one line with the starting 8 hashcode characters
  • git diff - shows the modifications and updations in the file between the commits
  • git stash - stores our commit in a hidden place and we can make changes to the file prior that commit
  • git stash pop <{head-path}> - returns the previously stashed commit
  • git log --merge- returns the list of commits which are causing merge conflicts
  • git log --after:returns the commits done after the mentioned date
  • git log --before:returns the commits done before the mentioned date
  • git branch : Creates a new branch with the specified branch name
  • git checkout : navigates and makes the head pointer points towards the specific branch
  • git checkout -b : creates and navigates to the created branch
  • git merge : Merges one branch with another branch
  • fork: creates a copy of an existing repo in the user's remote repo
  • git clone creates a copy of files of existing repo in the local repo of the user
  • git push origin: lets you move local branch into the remote repository
  • git pull origin: lets you move your remote branch into the local repo
  • git fetch: downloads the copy of a branch from another repo but doesn't integrate it with your local repo
  • ls : gives the list of files in the current working branch

Advanced Git:

  • git reset : undo's the changes made in the commit and puts it into staging area
  • git reset --soft: undo's the changes made in the commit and puts them in non committed area
  • git reset --hard:undo's the changes made in the respective commit and deletes the changes. Once used they are deleted permanantly.
  • git reset --mixed: It works the same as 'git reset'
  • git merge --abort : aborts the merging process
  • git merge --reset: undo's the merging process and puts back the commits in the state as they were before merging process
  • git rebase -i HEAD~: deletes a specifc commit
  • git rebase --abort: aborts the deletion of a branch
  • Git rebase : acts same as git merge but moves the commits of entire feature branch on top of the master branch
  • Git rebase –i HEAD~ : interactive rebase helps in manipulating the commits. Ex: squash is used to combine two commits, reword is used to edit the commit message.

  • Git revert: undo commits in a branch and creates a new commit

  • Find .git/objects -type f : displays the staged files present in git in the form of objects

  • Git cat-file –t : displays the type of object

  • Git cat-file –p : displays the content present in the object

  • Git gc –aggressive : performs compression on stored git objects freeing up disk space. It identifies a group of similar objects and compress them into a ‘pack’.

  • Git verify-pack –v .git/objects/pack/pack: displays the contents of a pack

  • Git reflog : gives the history of everything done in local repo

  • Git reflog expire –-expire=now –-expire-unreachable=now –all: expire all entries to the reflog that are older than now

  • Git show : inspects a commit

Top comments (0)