8 categories of Git

You can classify Git version control mechanism into 8 categories.

Create
Track
Revert
Update
Publish
View
Branch
Conflict

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

Create

When it comes to fi…


This content originally appeared on DEV Community and was authored by Danyson

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_B
git clone git://url
git 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 commited
git mv prev_place target_place //moves files
git rm files //removes files from working directory but adds it to the staging index
git 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 branch

git commit -a --amend //replaces previous commit

git checkout <commit_id>

Update

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

git fetch //from the original repo that you have forked
git fetch remote
git pull //fetch & merge
git am -3 patch.mbox
git 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 changes
git format-patch origin //create set of diffs
git push remote //push to origin or remote
git tag //mark current version

View

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

git status
git diff old_id new_id
git log -p file|dir
git blame file
git show id //meta data & diff
git show id:file
git branch //can list all branches both local and remote
git tag -l //shows list

Branch

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

git checkout branch //switch working dir to branch
git merge branch //merge into current branch
git branch branch_name //branch current
git 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 --ours
git diff --theirs
git log --merge
gitk --merge

Reference

git documentation

Personal blog@danyson.github.io


This content originally appeared on DEV Community and was authored by Danyson


Print Share Comment Cite Upload Translate Updates
APA

Danyson | Sciencx (2021-06-25T22:42:13+00:00) 8 categories of Git. Retrieved from https://www.scien.cx/2021/06/25/8-categories-of-git/

MLA
" » 8 categories of Git." Danyson | Sciencx - Friday June 25, 2021, https://www.scien.cx/2021/06/25/8-categories-of-git/
HARVARD
Danyson | Sciencx Friday June 25, 2021 » 8 categories of Git., viewed ,<https://www.scien.cx/2021/06/25/8-categories-of-git/>
VANCOUVER
Danyson | Sciencx - » 8 categories of Git. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/25/8-categories-of-git/
CHICAGO
" » 8 categories of Git." Danyson | Sciencx - Accessed . https://www.scien.cx/2021/06/25/8-categories-of-git/
IEEE
" » 8 categories of Git." Danyson | Sciencx [Online]. Available: https://www.scien.cx/2021/06/25/8-categories-of-git/. [Accessed: ]
rf:citation
» 8 categories of Git | Danyson | Sciencx | https://www.scien.cx/2021/06/25/8-categories-of-git/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.