Git & GitHub
Tutorial on using Git and GitHub
YouTube Video: [link]((375) Complete Git and GitHub Tutorial for Beginners - YouTube)
Cheatsheet
Commands: [Link](git-cheat-sheet-education (mycourse.app))
Git
-> is a version control system. It is popular, free, & open source.
Uses:
Tracking History
To collaborate
GitHub
-> Website that allows developers to store and manage their code using Git.
Terminologies:
repository: Folders created in GitHub.
commit: to final changes.
add: changes that have been made (add --> commit)
Setting up Git
-> Install Windows (git bash)
Configuring Git:
There are two type of changes:
Global: configuring for every repo.
Local: configuring for specific accounts with specific accounts.
Clone & Status:
clone: cloning a repo in our local machine
git clone <link of repo>
status: display the status of the code
git status
Git Status:
untracked: new files that git has not tracked yet.
modified: files that have been changed
staged: The file is ready to be committed
unmodified: unchanged
Add & Commit:
add: adds new or changed files in your working directory to the Git staging area.
git add <file name>
commit: it is the record of change
git commit -m <some message>
Push:
push: upload local (machine) repo content to remote (GitHub) repo.
git push origin main
Init:
-> used to create a new git repo
Workflow
GitHub Repo -> clone -> changes -> add -> commit -> push
Git Branches
-> If there are a number of groups working on a project, you may need different branches to commit changes to the project for different groups.
Branch Commands
Merging Code
Way 1
Way 2 -> Create PR (pull request)
PR (pull request): It lets you tell others about changes you've pushed to a branch in a repo on GitHub.
Pull Command:
-> used to fetch and download content from the remote repo and immediately update the local repo to match that content.
Resolving Merge Conflicts
-> An event that takes place when Git is unable to automatically resolve differences in code between two commits of two different branches.
Now, VS Code will show an error (CONFLICT) that, it is unable to decide whose branch's code to keep. It will give you an option on which branch's code to keep. You can also make the changes manually by deleting snippets of code.
After resolving the merge conflict, you'll have to add
and commit
that code again.
Undoing Changes
Case 1: staged changes (things have been added but not commit)
Case 2: commit changes (for one commit)
![[Pasted image 20231005205857.png]]
Case 3: commit changes (for many commits)
A hash of a commit can be obtained by using the following command:
Fork
-> A fork is a new repo that shares code and visibility settings with the original "upstream" repo. Fork is a rough copy.
You can fork other users' repos in your account, make changes (adding features, fixing bugs, etc.), and then request to merge it to their original repo. This is how you can work on other projects.
Last updated