- Introduction
- Configuring Git for the First Time
- General Git Features
- Git Help
- Git Branching
- Working with GitHub
- Git Undo
Git is a version control system that helps you keep track of code changes and collaborate on code with other developers.
- Git is widely used by over 70% of developers.
- Developers can work together from anywhere in the world.
- Git allows you to see the full history of the project.
- Git helps developers revert to earlier versions of a project.
- When a file is changed, added, or deleted, it is considered modified.
- Modified files can be staged and then committed to store a permanent snapshot.
- Git allows you to see the full history of every commit.
- You can revert back to any previous commit.
- Git keeps track of changes in each commit rather than storing a separate copy of every file.
- GitHub is a platform that provides tools to use Git effectively.
- It is the largest host of source code in the world, owned by Microsoft since 2018.
- GitHub allows developers to collaborate on projects remotely.
To set up your Git for the first time:
$ git config --global user.name "<Enter your username here>"
$ git config --global user.email "<Enter your email here>"Git will start tracking changes in the current folder:
$ git initStaging individual files:
$ git add <filename with extension>Staging all files in a folder:
$ git add --all
$ git add -A
$ git add .Adding commits helps keep track of progress and changes:
$ git commit -m "<Enter your message here>"Committing without staging first:
$ git commit -a -m "<Enter your message here>"View the status of files:
$ git status
$ git status --short # Compact viewView commit history:
$ git log
$ git log --onelineView help for specific commands:
$ git <command> -helpSee all available options:
$ git help --allTo exit list view, press SHIFT + G to jump to the end and q to exit.
Branches allow working on different parts of a project without impacting the main branch. Once work is complete, branches can be merged back.
$ git branch <name of branch>$ git branch$ git checkout <branch name>$ git checkout -b <branch name>$ git branch -d <branch name>It’s preferred to switch to the master branch before merging:
$ git merge <branch name>Add a remote repository:
$ git remote add origin <paste copied URL here>Push the master branch to GitHub and set it as default:
$ git push --set-upstream origin masterPush changes to GitHub after the initial setup:
$ git push originPull changes from a remote repository:
$ git pull originList all branches:
$ git branch -a # All branches
$ git branch -r # Only remote branchesCheckout and pull a branch:
$ git checkout <branch name>
$ git pullCreate a new branch and push it to GitHub:
$ git checkout -b <branch name>
$ git commit -a -m "<Message>"
$ git push origin <branch name>Clone a repository:
$ git clone <copied URL>Clone to a specific folder:
$ git clone <copied URL> <folder name>Revert to a previous commit:
$ git log --oneline # Find commit hash
$ git revert HEAD --no-edit # Revert the latest commitRevert to an earlier commit:
$ git revert HEAD~<x> # 'x' represents the number of commits backReset the repository to a previous commit:
$ git reset <commithash>Undo reset (reset back to a specific commit):
$ git reset <commithash>Modify the most recent commit:
$ git commit --amend -m "<Commit Message>"Amend files:
- Stage the changes.
- Amend with:
$ git commit --amendThanks for reading!
This `NOTES.md` file provides a structured and easy-to-read guide for using Git and GitHub, organized in a logical manner with clear explanations of each topic.