Course: Git and GitHub Provider: 365 Data Science
Course Link: https://365datascience.com/courses/git-and-github/
Git is a distributed version control system that tracks changes in files and enables collaboration among developers.
GitHub is a cloud-based platform for hosting Git repositories, collaborating with others, reviewing code, and managing software projects.
Download and install Git from:
Check the installed version:
git --versionDisplay general help:
git --helpDisplay help for a specific command:
git help initConfigure your Git username:
git config --global user.name "My Name"Configure your email address:
git config --global user.email "name@domain.com"It is recommended to use the same email address as your GitHub account so commits are correctly associated with your profile.
Set the default editor:
git config --global core.editor "notepad"Create a test file:
notepad testdocument.txtView the current Git configuration (Press q to quit):
git config --listInitialize a Git repository:
git initCheck the repository status:
git statusStart tracking a file (Stage the file):
git add list.txtCreate a commit:
git commit -m "Create shopping list"View commit history:
git logCheck repository status:
git statusView changes in the working directory:
git diffStage changes:
git add list.txtCommit the changes:
git commit -m "Added fruits and vegetables"Display only the latest commit:
git log -1Show differences between the working directory and the staging area:
git diffShow differences between the staging area and the last commit:
git diff --staged(Equivalent:)
git diff --cachedCompare a previous commit with the current working tree:
git diff <commit-hash>Example:
git diff 3cb2d5789aaHEAD is a reference (pointer) to the currently checked-out commit, usually the latest commit on the current branch.
Restore a file from three commits earlier:
git checkout HEAD~3 -- list.txtRestore the latest committed version of the file:
git checkout HEAD -- list.txtNote: In modern Git,
git restoreis preferred overgit checkoutfor restoring files.
Unstage a file without losing changes:
git reset list.txtMove HEAD back one commit while keeping changes staged:
git reset HEAD~1 --softMove HEAD back one commit and unstage the changes while keeping the file contents:
git reset HEAD~1 --mixedMove HEAD back one commit and discard all changes:
git reset HEAD~1 --hard??
--hardpermanently deletes uncommitted changes. Use it with caution.
Create a branch:
git branch dairyList branches:
git branchCreate another branch:
git branch meatSwitch to a branch:
git checkout dairyReturn to the main branch:
git checkout masterMerge another branch into the current branch:
git merge meatNewer Git versions use
maininstead ofmasteras the default branch name.
Add a remote repository:
git remote add origin https://github.com/PythonJournalist/git_practice.gitVerify the remote:
git remote -vPush the local repository:
git push origin masterIf your default branch is
main, use:
git push origin mainClone a repository:
git clone https://github.com/medical_dataset/data.gitDownload changes from the remote repository:
git fetchDownload and merge changes:
git pullThis course introduced the fundamentals of Git and GitHub, including:
- Installing and configuring Git
- Creating repositories
- Tracking and committing changes
- Viewing history with
git log - Comparing changes with
git diff - Understanding
HEAD - Undoing changes using
git reset - Working with branches
- Connecting to GitHub
- Cloning, fetching, pulling, and pushing repositories
Completed.
This repository contains my notes while completing the Git and GitHub course from 365 Data Science. It covers the essential Git commands and GitHub workflows needed for version control and collaboration.