➔ 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 💚