Skip to content

Latest commit

 

History

History
149 lines (116 loc) · 2.76 KB

Git & GitHub.md

File metadata and controls

149 lines (116 loc) · 2.76 KB

Problem Git and Gitlab solves

  1. Suppose 2 people are working on a project and want a centralized code base, To be on the same page we can use tools like gitlab and github
  2. Git on the other hand helps us to manage the code in a local machine to manage various versions of a particular codebase. so that we can revert back whenever needed.

Extensions Required

  1. git blame
  2. git autoconfig
  3. github theme

Global Configurations

1. git config --global user.name "username"
2. git config --global user.email "email"
3. git config --global core.editor "code --wait"
4. git config --global core.autocrlf "input"
5. git config --global -e

Stages of files in git

  1. U : Untracked files
  2. A : Added or Staged
  3. C : Committed
  4. M : Modified

Basic git setup on local machine

  • Making git available on a project
	git init
  • Making files staged
	git add . or file-names
  • Commit the files
	git commit -m "commit-message"
  • Find total checkpoints/commits
	git log --oneline
  • Going or reverting back to previous commits
	git reset --hard HEAD~1

This commands reverts to previous commit.

Branching

  • Creation of branch
	git branch branch-name
  • List of all branches
	git branch
  • Checkout
	git switch branch-name
  • Git branch from a reference
	git branch -b branch-name from-branch
  • Create a branch and checkout
	git branch -b branch-name
  • Delete a branch
	git branch -d branch-name

Merging

  • Merging in Git refers to the process of integrating changes from one branch into another.
  • Before merging always comeback to main
	git checkout main
	git merge branch-name
	git add . or file-names
	git commit -m "commit-message"

Handling Conflicts

  • Conflicts occurs only while merging
  • There are three types of conflicts
    1. Accept current change -- main
    2. Accept incoming change -- feature branch
    3. Accept both change -- Both main and feature
  • Add and Commit the changes

Collaboration using Git & GitLab

  1. Owner or Lead makes the default code setup.
	git init
	git add . 
	git commit -m "MESSAGE"
	git branch -M main 
	git remote add origin URL
	git push -u origin main
  1. Add Collaborators
  2. Collaborators Overview
    • Collaborator should always create a sub-branch and only make changes to it.
	git clone URL
	git Switch -C branch_name
	git add .
	git commit -m "COMMIT MESSAGE"
	git push -u origin main branch-name
  • Once the main or parent branch is updated
	git switch main/parent
	git pull
  1. Once the collaborator work is done and pushed.
	git fetch
	git switch branch-name : code-review
	git switch main
	git merge branch-name
	git push origin-main