β Free and openSource version control system ( vcs means tools that help to track changes in code )
β VCS track history and it helps to collaborate
β Website where we host repositories online
β we can also track our initiate , update , delete history.
β generally we create files/folders using mouse but we can create them using terminal. Likewise, we can directly upload on github but a good developer prefer to do changes using Terminal.
βββββββββββββββββββββββββββββ
β Git is already installed in macOs and Linux. But, in windows we are installing Git-Bash which already have git
β check that git installed or not git --version
if any version available then git is installed
β ways to use git
- Command line -- popular way
- IDE/code editors like VScode
- Graphical user interface like GitKraken
βββββββββββββββββββββββββββββ
" <name> "
so the answer of this is "parth"
βββββββββββββββββββββββββββββ
βοΈ git config --global user.name "<userName>"
(write username at userName)
βοΈ git config --global user.email "<[email protected]>"
(enter your email)
βοΈ git config --list
(to check that details are saved or not )
βββββββββββββββββββββββββββββ
β we can also open intergrated terminal with vscode (From the menu, use the Terminal > New Terminal or View > Terminal menu commands)
β same as terminal/git-bash
βββββββββββββββββββββββββββββ
βοΈ git clone <link>
= clone = cloning a repository on our local machine
π€ how to generate links - go to the repo on gitHub and there is button named CODE click there and copy HTTPS link
βοΈ git status
= status = display the state of code
βοΈ git add <fileName>
= adds new or changed files in working directory to the git staging area
βοΈ git commit -m "some message"
= record the change
βοΈ git push origin main
= upload local repo content to remote repo
β»οΈ first clone the github repo on local machine , then check git status , if any file which created newly is untracked then do git add then if we do some changes in that file then again do git commit means save , then if we want to push/upload this file on github then do git push origin main
βββββββββββββββββββββββββββββ
β sometimes we started to create project from scratch in our local system and if we want to make new repo then
βοΈ git init
=
βοΈ git remote add origin <link>
= we are adding the link of repo where we want to push our folders from local system
βοΈ git remote -v
= to verify remote
βοΈ git branch
= to check branch name
βοΈ git branch -M main
= to rename branch name to "main"
βοΈ git push origin main
βββββββββββββββββββββββββββββ
β it creates the duplicate of main/master branch to work on features or fix bugsv
βββββββββββββββββββββββββββββ
βοΈ git branch
= to check branch
βοΈ git branch -M main
= to rename branch
βοΈ git checkout <branch-name>
= to navigate
βοΈ git checkout -b <new-branch-name>
= to create new branch
βοΈ git branch -d <branch-name>
= to delete branch
βββββββββββββββββββββββββββββ
β merging branches
βοΈ git diff <branch-name>
= to compare commits,branches,files
βοΈ git merge <branch-name>
= to merge 2 branches
OR create a PR(Pull Request)
π Pull Request
β it lets you tell others about the changes you have pushed to a branch in a repo on github
β we can get the button "Compare & pull request" of PR at the github repo for merging
βββββββββββββββββββββββββββββ
β Now the changes are already done on github using PR from github web and so there is not any changes on our local working system and so we have to do Pull command to see the same repo as github ( first push and then pull )
βοΈ git pull origin main
βββββββββββββββββββββββββββββ
β like we have 2branches and at the same place there are different chnages available and so there is conflict
β Vs code already have feature it will ask about it and then you have to select the changes or that is your wish what will be the change
βββββββββββββββββββββββββββββ
1οΈβ£ Staged (git status) changes
βοΈ git reset <fileName>
(for remove change the particular file)
βοΈ git reset
(for remove the change for all files)
2οΈβ£ commited changes(for one commit)
βοΈ git reset HEAD~1
(here head pointer is pointing last commit)
3οΈβ£ commited changes(for many commits)
βοΈ git reset <commit-hash>
βοΈ git reset --herd <commit-hash>
βββββββββββββββββββββββββββββ
β a fork is newrepo that shares code and visibility settings with original "upstream" repo
β fork is rough copy
β usage- open source contribution
βββββββββββββββββββββββββββββ
git diff
βββββββββββββββββββββββββββββ
https://stackoverflow.com/questions/19032296/how-to-use-git-revert
git log
git log --oneline
git revert <versionId>
git reset <versionId>
βοΈπ cheatSheet
β»οΈ @ Created by Parth with π