├── .gitignore ├── LICENSE ├── README.md └── docs ├── 1_intro.md ├── 2_demo.md ├── 3_actions.md ├── 4_packages.md └── img ├── ContinuousIntegration.png ├── Git1.png ├── GitHub.png ├── SDLC_SCM.png ├── Upstream.png ├── Upstream2.png ├── VersionControl.png ├── actions.png ├── chatgpt-vcs.png ├── cicd.png ├── file.png ├── git-components.png ├── git.png └── versions.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nishkarsh Raj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction to Git and GitHub 2 | 3 | ## Table of contents 4 | 5 | * [Introduction to Git and GitHub](docs/1_intro.md) 6 | 7 | * [Using GitHub for Version Control - Demo](docs/2_demo.md) 8 | 9 | * [Introduction to GitHub Actions](docs/3_actions.md) 10 | 11 | * [Introduction to GitHub Packages](docs/4_packages.md) 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/1_intro.md: -------------------------------------------------------------------------------- 1 | # Introduction to Git and GitHub 2 | 3 | **Source Code Management:** Source code management is the process of tracking and managing changes to the software over the software development lifecycle. 4 | 5 | ### Components of Source Code Management 6 | 7 | * Repository 8 | 9 | * Server 10 | 11 | * Client 12 | 13 | * Working Directory 14 | 15 | * Trunk 16 | 17 | ![](img/git-components.png) 18 | 19 | ### Version Control System (VCS) 20 | 21 | ![](img/chatgpt-vcs.png) 22 | 23 | ![VCS](img/VersionControl.png) 24 | 25 | ### Git 26 | 27 | ![image](img/Git1.png) 28 | 29 | * Git is a **distributed version control system** used for managing the source code in software development by tracking changes to files and coordinating work among **multiple users**. 30 | 31 | * Git is released as **free** software under the terms of the **GNU General Public License** version 2 or later. 32 | 33 | * Git perceives the information as a series of **snapshots** of files. Git takes a snapshot of how files look like at the moment when a project is committed or saved and it stores a reference to that snapshot of files. 34 | 35 | * As an **efficient version control system**, Git does not store snapshot of files again if nothing has changed in the file and it only stores a link to the previous identical snapshot of the file it has already stored. 36 | 37 | #### Coherence and file tracking using Git VCS 38 | 39 | * Git version control system assigns a checksum to every file or directory before it is stored and the file or directory is referenced by that **checksum**. 40 | 41 | * The checksum is usually a **40-character string which is composed of hexadecimal characters (a-f and 0-9)** and it is calculated depending on the contents of a file or directory in Git. 42 | 43 | * **Git uses SHA-1 hash mechanism for checksumming**. 44 | 45 | * The SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash algorithm which generates a checksum from a sequence of bytes of any length in a file or a directory. 46 | 47 | #### Three main sections of a Git Project 48 | 49 | * Working Directory 50 | 51 | * Staging Area 52 | 53 | * Git Directory 54 | 55 | ![Git Working directories](img/git.png) 56 | 57 | #### Three states of a file in Git Project 58 | 59 | * Modified 60 | 61 | * Staged 62 | 63 | * Committed 64 | 65 | ![File States](img/file.png) 66 | 67 | #### Features of Git 68 | 69 | * Non-Linear Development Support 70 | 71 | * Distributed Development 72 | 73 | * Compatibility 74 | 75 | * Large Projects Handling 76 | 77 | * Encryption of History 78 | 79 | * Toolkit based Design 80 | 81 | * Flexible merges 82 | 83 | * Garbage collection 84 | 85 | * Periodic Packing of files 86 | 87 | ### Basic Functionalities of Source Code Management 88 | 89 | * Add 90 | 91 | * Check Out 92 | 93 | * Check In 94 | 95 | * Check In message 96 | 97 | * Revision 98 | 99 | * Head 100 | 101 | * Changelog 102 | 103 | * Revert 104 | 105 | ### Features of SCM 106 | 107 | * Backup and Restore 108 | 109 | * Synchronize 110 | 111 | * Earlier version review 112 | 113 | * Recent version restore 114 | 115 | * Version History 116 | 117 | * Owner History 118 | 119 | * Testing Environment 120 | 121 | * Branching and Merging 122 | 123 | ### CI/CD 124 | 125 | ![](https://www.suse.com/assets/img/devops-process.png) 126 | 127 | In continuous integration practice, a **centralized server** regularly retrieves all new changes to the source code by developers and builds the **software application from scratch.** 128 | 129 | The **build and testing of the software is automated and every change or iteration to the software triggers an automated test run to ensure the desired delivery quality.** The central repository is always kept updated in continuous integration practice. 130 | 131 | Continuous deployment is the process of building, testing, and releasing the software from the build environment into the production environment automatically without human intervention. Continuous deployment automates the entire testing process and performs more tests on code blocks compared to the usual unit testing done on the code. 132 | 133 | ![SDLC with SCM](img/SDLC_SCM.png) 134 | 135 | ### GitHub 136 | 137 | ![GitHub](img/GitHub.png) 138 | 139 | GitHub is a cloud based repository hosting service for Git VCS. 140 | 141 | ## Important Links and References 142 | 143 | [Download Git Bash](https://git-scm.com/downloads) 144 | 145 | [Read the Official Pro-Git E-book](https://git-scm.com/book/en/v2) 146 | 147 | [GitHub Education Pack](https://education.github.com/pack) 148 | 149 | [Introduction to Markdown](https://github.com/NishkarshRaj/Markdown-for-Documentation) 150 | 151 | [Github Docs](https://docs.github.com/en) -------------------------------------------------------------------------------- /docs/2_demo.md: -------------------------------------------------------------------------------- 1 | # Getting started with GitHub - Demonstration 2 | 3 | ## Tracking a local project using Git VCS 4 | 5 | * Initialize the working directory as a Git repository 6 | 7 | ``` 8 | $ git init 9 | $ ls -a 10 | ``` 11 | 12 | * Configure your local system with your GitHub Host credentials 13 | 14 | ``` 15 | $ git config --global user.name "[GitHub/GitLab username]" 16 | ``` 17 | 18 | ``` 19 | $ git config --global user.email "[GitHub/Gitlab Primary Email]" 20 | ``` 21 | 22 | * Check states of the files present in the working directory 23 | 24 | ``` 25 | $ git status 26 | ``` 27 | 28 | * Add/modify files via command line or via GUI 29 | 30 | ``` 31 | $ git [add/stage] [filename].[extension] 32 | ``` 33 | 34 | * Add all the changed files 35 | 36 | ``` 37 | $ git [add/stage] . 38 | ``` 39 | 40 | * Check in the code to Git version history 41 | 42 | ``` 43 | $ git commit -m "[Commit Message]" 44 | ``` 45 | 46 | * Create a link between local directory and GitHub repository 47 | 48 | ``` 49 | $ git remote add origin [Repository URL] 50 | ``` 51 | 52 | * Push the local commits to remote repository 53 | 54 | ``` 55 | $ git push -u origin master 56 | ``` 57 | 58 | * See the logs of the commit history 59 | 60 | ``` 61 | $ git log 62 | ``` 63 | 64 | #### Commit versus Push Command 65 | 66 | * Commits store snapshots with commit id and timestamp of the Git Version 67 | 68 | * Push command synchronizes the local commit history with the remote commit history. 69 | 70 | ## Working on Git projects locally 71 | 72 | * Clone the git repository to local machine 73 | 74 | ``` 75 | $ git clone [Repository URL] 76 | ``` 77 | 78 | * See the git commit history locally 79 | 80 | ``` 81 | $ git log 82 | ``` 83 | 84 | ### GitHub Best Practices 85 | 86 | `1. Use meaningful commit messages:` Make sure your commit messages are clear and concise, and describe the changes you made in the commit. 87 | 88 | `2. Keep your repository organized:` Keep your repository organized by using folders to group related files together. Use descriptive names for your files and folders. 89 | 90 | `3. Use branches:` Use branches to work on new features or bug fixes without affecting the main codebase. This allows you to experiment with new ideas without worrying about breaking the main code. 91 | 92 | `4. Use pull requests:` Use pull requests to review and merge changes into the main codebase. Pull requests allow you to get feedback on your changes before they are merged into the main codebase. 93 | 94 | `5. Use issues:` Use issues to track bugs, feature requests, and other tasks. Issues allow you to track progress and communicate with other contributors. 95 | 96 | `6. Use comments and discussions:` Use comments and discussions to communicate with other contributors. This can help you get feedback on your changes and collaborate more effectively. 97 | 98 | `7. Use GitHub Actions:` GitHub Actions allow you to automate common tasks, such as running tests or deploying your code. This can help you save time and reduce errors. 99 | 100 | `8. Follow best practices for security:` Follow best practices for security, such as using strong passwords, enabling two-factor authentication, and reviewing access permissions regularly. 101 | 102 | `9. Keep your repository up-to-date:` Keep your repository up-to-date by pulling in changes from other contributors regularly. This can help you avoid conflicts and ensure that your code is compatible with the latest changes. 103 | 104 | `10. Document your code:` Document your code to make it easier for others to understand and use. Use clear and concise comments to describe what your code does, how it works, and any limitations or dependencies. 105 | 106 | - [ ] [Readme](https://github.com/NishkarshRaj/Markdown-for-Documentation) 107 | 108 | - [ ] [License](https://opensource.org/licenses/) 109 | 110 | - [ ] [GitIgnore](https://github.com/github/gitignore) 111 | 112 | - [ ] [Dependabot](https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates) 113 | 114 | ```yaml 115 | version: 2 116 | updates: 117 | - package-ecosystem: "npm" # See documentation for possible values 118 | directory: "/" # Location of package manifests 119 | schedule: 120 | interval: "weekly" 121 | ``` 122 | 123 | ## Contributing to Upstream GitHub Projects 124 | 125 | ![Upstream](img/Upstream2.png) 126 | 127 | **1. Fork the repository** 128 | 129 | **2. Work locally on the changes** 130 | 131 | **2.1 Work on a feature branch** 132 | 133 | * Create a new feature branch 134 | 135 | ``` 136 | $ git branch [branch name] 137 | $ git branch 138 | ``` 139 | 140 | * Move from current branch to the destination branch 141 | 142 | ``` 143 | $ git checkout [branch name] 144 | ``` 145 | 146 | * Stage files on the current branch 147 | 148 | ``` 149 | $ git add [files] 150 | ``` 151 | 152 | * Commit the changes as a snapshot 153 | 154 | ``` 155 | $ git commit -m "[Commit Message]" 156 | ``` 157 | 158 | * Check the commit history in terms of branches 159 | 160 | ``` 161 | $ git log --oneline --all --decorate --graph 162 | ``` 163 | 164 | * Push changes from the current branch to our forked repository 165 | 166 | ``` 167 | $ git push -u origin [branch name] 168 | ``` 169 | 170 | **3. Create a Pull Request** 171 | 172 | ### Synchronize forked repository with upstream repository 173 | 174 | * Link the forked repository with the upstream repository. 175 | 176 | ``` 177 | $ git remote -v 178 | $ git remote add upstream [Upstream Repository URL] 179 | ``` 180 | 181 | * Fetch the changes from upstream repository to the forked repository 182 | 183 | ``` 184 | $ git fetch upstream 185 | ``` 186 | 187 | * Merge the fetched changes with the master branch of the repository 188 | 189 | ``` 190 | $ git merge upstream/master 191 | ``` 192 | 193 | 194 | * Push the new commit history to forked repository 195 | 196 | ``` 197 | $ git push 198 | ``` 199 | 200 | ## Important Miscellaneous Git commands and utilities 201 | 202 | * .gitignore 203 | 204 | * logs 205 | 206 | * diff 207 | 208 | * branch 209 | 210 | * revert and reset 211 | 212 | * merge and rebase 213 | 214 | ## Important Links and References 215 | 216 | [GitHub Skills Training](https://skills.github.com/) 217 | 218 | [GitHub Upstream Contribution commands cheat sheet](https://statusneo.com/github-upstream-contributions-cheetsheet/) 219 | 220 | [Up For Grabs](https://up-for-grabs.net/#/) 221 | -------------------------------------------------------------------------------- /docs/3_actions.md: -------------------------------------------------------------------------------- 1 | # Introduction to GitHub Actions 2 | 3 | ### Continuous Integration 4 | 5 | ![CI](img/ContinuousIntegration.png) 6 | 7 | In continuous integration practice, a centralized server regularly retrieves all new changes to the source code by developers and builds the software application from scratch. 8 | 9 | The build and testing of the software is automated and every change or iteration to the software triggers an automated test run to ensure the desired delivery quality. The central repository is always kept updated in continuous integration practice. 10 | 11 | ### Continuous Deployment 12 | 13 | ![CICD](img/cicd.png) 14 | 15 | ### GitHub Actions 16 | 17 | ![Actions](img/actions.png) 18 | 19 | ### A template GitHub Action - Create React App 20 | 21 | ```yaml 22 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 23 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs 24 | 25 | name: Node.js CI 26 | 27 | on: 28 | push: 29 | branches: [ "main" ] 30 | pull_request: 31 | branches: [ "main" ] 32 | 33 | jobs: 34 | build: 35 | 36 | runs-on: ubuntu-latest 37 | 38 | strategy: 39 | matrix: 40 | node-version: [14.x, 16.x, 18.x] 41 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 42 | 43 | steps: 44 | - uses: actions/checkout@v3 45 | - name: Use Node.js ${{ matrix.node-version }} 46 | uses: actions/setup-node@v3 47 | with: 48 | node-version: ${{ matrix.node-version }} 49 | cache: 'npm' 50 | - run: | 51 | npm install 52 | ``` 53 | 54 | ## Important Links and References 55 | 56 | [GitHub Actions](https://github.com/features/actions) 57 | 58 | [GitHub Actions Help](https://help.github.com/en/actions) 59 | 60 | [Learn Docker](https://iq.opengenus.org/basics-of-using-docker/) 61 | 62 | [GitHub Actions Blog](https://iq.opengenus.org/github-actions-using-container-scripts/) 63 | 64 | [Actions Checkout Repository](https://github.com/actions/checkout) 65 | 66 | [GitHub Marketplace](https://github.com/marketplace) 67 | 68 | 69 | -------------------------------------------------------------------------------- /docs/4_packages.md: -------------------------------------------------------------------------------- 1 | # Introduction to GitHub Packages 2 | 3 | ### Pushing Docker Images on GitHub Packages 4 | 5 | * `Dockerfile` 6 | 7 | ```dockerfile 8 | FROM node:14-alpine 9 | WORKDIR /usr/src/app 10 | COPY . . 11 | RUN npm install 12 | EXPOSE 3000 13 | CMD [ "npm", "start" ] 14 | ``` 15 | 16 | - `.dockerignore` 17 | 18 | ``` 19 | node_modules/ 20 | ``` 21 | 22 | - `Docker Build And Push Actions` 23 | 24 | ```yaml 25 | name: Create and publish a Docker image 26 | 27 | on: push 28 | 29 | env: 30 | REGISTRY: ghcr.io 31 | IMAGE_NAME: ${{ github.repository }} 32 | 33 | jobs: 34 | build-and-push-image: 35 | runs-on: ubuntu-latest 36 | permissions: 37 | contents: read 38 | packages: write 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v3 43 | 44 | - name: Log in to the Container registry 45 | uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 46 | with: 47 | registry: ${{ env.REGISTRY }} 48 | username: ${{ github.actor }} 49 | password: ${{ secrets.GITHUB_TOKEN }} 50 | 51 | - name: Extract metadata (tags, labels) for Docker 52 | id: meta 53 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 54 | with: 55 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 56 | 57 | - name: Build and push Docker image 58 | uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 59 | with: 60 | context: . 61 | push: true 62 | tags: ${{ steps.meta.outputs.tags }} 63 | labels: ${{ steps.meta.outputs.labels }} 64 | ``` 65 | 66 | ## Important Links and References 67 | 68 | [Official GitHub Packages Website](https://github.com/features/packages) 69 | 70 | [GitHub Packages Community Page](https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages) 71 | 72 | [Play With Docker](https://labs.play-with-docker.com/) 73 | -------------------------------------------------------------------------------- /docs/img/ContinuousIntegration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/ContinuousIntegration.png -------------------------------------------------------------------------------- /docs/img/Git1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/Git1.png -------------------------------------------------------------------------------- /docs/img/GitHub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/GitHub.png -------------------------------------------------------------------------------- /docs/img/SDLC_SCM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/SDLC_SCM.png -------------------------------------------------------------------------------- /docs/img/Upstream.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/Upstream.png -------------------------------------------------------------------------------- /docs/img/Upstream2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/Upstream2.png -------------------------------------------------------------------------------- /docs/img/VersionControl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/VersionControl.png -------------------------------------------------------------------------------- /docs/img/actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/actions.png -------------------------------------------------------------------------------- /docs/img/chatgpt-vcs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/chatgpt-vcs.png -------------------------------------------------------------------------------- /docs/img/cicd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/cicd.png -------------------------------------------------------------------------------- /docs/img/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/file.png -------------------------------------------------------------------------------- /docs/img/git-components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/git-components.png -------------------------------------------------------------------------------- /docs/img/git.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/git.png -------------------------------------------------------------------------------- /docs/img/versions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Introduction-to-Git-and-GitHub/02a3bfdab3e222d043297abcfa2cb7d8614346a2/docs/img/versions.jpg --------------------------------------------------------------------------------