Skip to content

Latest commit

 

History

History
165 lines (115 loc) · 7.23 KB

README.md

File metadata and controls

165 lines (115 loc) · 7.23 KB

Git-and-Github

❤️ What is Git ?

➔ Free and openSource version control system ( vcs means tools that help to track changes in code )
➔ VCS track history and it helps to collaborate

❤️ What is GitHub ?

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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💚 Using Git

➔ 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

  1. Command line -- popular way
  2. IDE/code editors like VScode
  3. Graphical user interface like GitKraken

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠️Note- everywhere in codes if i am using means you have to write proper thing at something expect < , > like " <name> " so the answer of this is "parth"


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💛 Configuring Git

✔️ 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 )

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💙 Git with VScode

➔ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💚 Basic commands

✔️ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💜 Init command - used to create new git repo

➔ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💚 Git branches

➔ it creates the duplicate of main/master branch to work on features or fix bugsv

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💚 branch commands

✔️ 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 code

➔ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🧡 Pull command

➔ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💛 Merge conflicts

➔ 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

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💚 Fixing Mistakes

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>

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💛 What is Forking ?

➔ a fork is newrepo that shares code and visibility settings with original "upstream" repo
➔ fork is rough copy
➔ usage- open source contribution

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

differance

git diff

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

revert to previous version

VvIxF 1_045T7UdsT40cRIwCAnUJ0w

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 💚