Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 25, 2021 10:42 pm GMT

8 categories of Git

You can classify Git version control mechanism into 8 categories.

  1. Create
  2. Track
  3. Revert
  4. Update
  5. Publish
  6. View
  7. Branch
  8. Conflict

Below i have given classification of git mechanism along with their important commands.

Create

When it comes to files

git init          git add .git add [filename]

When it comes to a repository

git clone ~/folder_A ~/folder_Bgit clone git://urlgit clone ssh://url

Track

Track is when we want to track our files for commit, update or delete operations.

git add files // adds files ready to be commitedgit mv prev_place target_place //moves filesgit rm files //removes files from working directory but adds it to the staging indexgit rm --cached files //stops tracking but keeps files in working directory

Revert

We use revert when we want to do a new
commit that undoes previous commits.

git reset --hard

The --hard mode is not recoverable so if you want to recover your files after a git reset --hard, follow these steps How to recover our commit after a git reset --hard ?
Other modes of reset ->--soft, --mixed, --merge, --recurse-submodules

git revert branchgit commit -a --amend //replaces previous commitgit checkout <commit_id>

Update

Update is when we want to bring changes to our files.

git fetch //from the original repo that you have forkedgit fetch remotegit pull //fetch & mergegit am -3 patch.mboxgit apply patch.diff

Publish

Publish is when we want to establish what we done with our files.

git commit -a //adds all changed files & commits all changesgit format-patch origin //create set of diffsgit push remote //push to origin or remotegit tag //mark current version

View

View is when we want to see the informations about our files.

git statusgit diff old_id new_idgit log -p file|dirgit blame filegit show id //meta data & diffgit show id:filegit branch //can list all branches both local and remotegit tag -l //shows list

Branch

The "branch" helps you to create, delete, and list branches.

git checkout branch //switch working dir to branchgit merge branch //merge into current branchgit branch branch_name //branch currentgit checkout -b new_branch another_branch //branch new branch from another branch and switch to new branch

Conflict

Conflict arises when two files of same name have different contents so we need to check the difference and maintain our code base without conflicts.

git diff [--base]git diff --oursgit diff --theirsgit log --mergegitk --merge

Reference

git documentation

Personal blog@danyson.github.io


Original Link: https://dev.to/danyson/8-categories-of-git-2127

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To