- 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
- 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.
- git blame
- git autoconfig
- github theme
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
- U : Untracked files
- A : Added or Staged
- C : Committed
- M : Modified
- 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.
- 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 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"
- Conflicts occurs only while merging
- There are three types of conflicts
- Accept current change -- main
- Accept incoming change -- feature branch
- Accept both change -- Both main and feature
- Add and Commit the changes
- 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
- Add Collaborators
- 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
- 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