Git & GitHub


Key Points:
What is Git? β git hai apke khud ke system par project manage krna.
What is GitHub? β agar vhi project management mujhe internet pe kahi CENTRAL CODEBASE mai krna ho.
GitHub in Two Aspects:
π¦ Self-Work Management
π¦ Collaboration
Basic Setups (One-Time only):
installing git
git config --global
user.name
βnameβ
To set up the name!git config --global
user.email
β
email@male.com
β
To set up the email!git config --global core.editor βcode --waitβ
To set the code editor we use!git config --global core.autocrlf
Can edit any command, anytime with the help of
git config --global -e
.
Installing some extensions on VS Code:
git auto-config
Git Blame
π‘ Note: If you have shown, around 10K changes in the source control section in VS Code. Then, use git init
in the vs code terminal of current folder. It will resolve the issue and git will track your current files in the folder.
Stages
U - untracked ??
A - added or staged A | M - modified M
C - committed (not visible)
Self-Work Management
git status -s
β to know current status of unstaged and staged files, before & after commit.
git log --oneline
β to know current status of saved points i.e **CHECKPOINTS made by commit.**
You can manage the tracking by **source control** in the VS code, or via git commands in terminal.
git reset --hard HEAD~***kitna_piche_jana_hai
β There are different types of git reset
:
git reset --hard HEAD~1
β erase the entire commit by 1git reset --soft HEAD~2
β erase the commit and put them back into staged area.git reset --mixed HEAD~1
β erase the commit and put them back into modified.
# git log --oneline
cb76ee4 wrong
01b56c6 test
2e407ce first commit
git revert cb76ee4
β will by default bring your files back to 01b56c6 and will add a further commit to your history:
8d4406b Revert "wrong"
cb76ee4 wrong
01b56c6 test
2e407ce first commit
git reset 01b56c6
β will instead bring your files back to 01b56c6 and will clean up any other commit after that from your history :
01b56c6 test
2e407ce first commit
To remove everything from .git
tracking, use del -rf .git
or rm -rf .git
Branching
git branch feature/any_feature
β To make a branch with name.git branch
β How many branches are there?git switch features/any_feature
β switched to any branch.git switch -C features/any_feature
β make branch as well as switch.git branch -d features/any_features
β deleting/removing any branch.
Merging
π‘ For merging, you must be in the main branch.
git merge features/any_features
β when no conflict is there, merge successfully.If conflict occur, choose:
Mainly used merging techniques:
fast forward merge β
here, you simply move the postion of head from current to the newly added branch. There is no merging actually!!
three-way merge β merging red dot branches =β making white one.
Stashing
git stash
β when switching to another branch without committing changes to the current branch.git stash apply
β then coming back to the branch and applying command to make the changes visible.git stash clear
β remove the stash being saved.
Cloning
git clone <git_repo>
β Clone the whole repo.git clone -b <branch> <remote_repo>
β Cloning the specific branch only.
Collaboration
π‘ Main steps to follow while collaboration:
Main banda folder and initial files bnayega.
Ab usse GitHub par daal dega.
Collaborators add krega.
π‘ Main steps to follow for collaborators:
Clone the repo of main banda.
(VERY IMP.) β Make your own branch,
NEVER MAKE CHANGES IN MAIN BRANCH.
Write your code in that branch only.
After completing β committing & pushing the code in that branch only.
Inform teammates to see your commits.
MERGER (Main banda) β fetch krega, merge krega then re-push kr dega in the main branch.
GitHub Stuff:
- Making a repo and copying every command from there.
echo "# a" >> README.md
git init
git add .
git commit -m "stage 0"
git branch -M main
git remote add origin <https://github.com/Yash2204V/a.git>
git push -u origin main
git add .
/git add file_name
git commit -m"any_message"
git -u push origin your_branch_name
π‘ When you make your branch: git branch -C feature/any_feature
β to quickly make and switch to your branch.
Merger work after collaborators did their work:
git fetch
git switch feature/any_feature
β checkout and review the code.Switch to the main branch.
git merge feature/any_feature
β both the codes are merged.git push origin main
β finally, the code is on GitHub π₯³
Then, Suppose the collaborative want to see his code in the main branch:
git switch main
git fetch
β Aya ki Nhi?git pull
β Ab aa jayega(fetch and merge)
Source: Sheryians Coding School
Loving the work, Harsh Sharma SIR put into making it. π
Subscribe to my newsletter
Read articles from Yash Varma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
