├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Pugazharasan Chandrasekar 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 | # Welcome to the Git and GitHub Learning Repository 🌟 2 | 3 | - [Welcome to the Git and GitHub Learning Repository 🌟](#welcome-to-the-git-and-github-learning-repository-) 4 | - [Getting Started 🚀](#getting-started-) 5 | - [Install Git 🛠️](#install-git-️) 6 | - [Command Breakdown 🛠️](#command-breakdown-️) 7 | - [Understanding Git Workflow 🌐](#understanding-git-workflow-) 8 | - [Git Workflow Overview 🔄](#git-workflow-overview-) 9 | - [Git Init 🏁](#git-init-) 10 | - [Git Add ➕](#git-add-) 11 | - [Git Commit 📝](#git-commit-) 12 | - [Git Branch 🌿](#git-branch-) 13 | - [Git Remote 🌐](#git-remote-) 14 | - [Git Push 🚀](#git-push-) 15 | - [Git Pull 🔄](#git-pull-) 16 | - [Git Checkout 🌿](#git-checkout-) 17 | - [Git Clean 🧹](#git-clean-) 18 | - [Basic Git Commands 💻](#basic-git-commands-) 19 | - [User Configuration 👤](#user-configuration-) 20 | - [Git Ignore 🚫](#git-ignore-) 21 | - [Learning Markdown 📝](#learning-markdown-) 22 | 23 | 24 | This repository has been created with the sole purpose of helping you learn and understand Git and GitHub. Whether you're a beginner taking your first steps into version control or looking to refine your skills, you're in the right place. 25 | 26 | ## Getting Started 🚀 27 | 28 | ## Install Git 🛠️ 29 | 30 | To get started with version control, you'll need to install Git, the popular distributed version control system. 31 | 32 | Follow the installation instructions for your operating system on the [official Git website](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). This will guide you through the process of downloading and installing Git on your machine. 33 | 34 | Once installed, you'll be ready to use Git for managing your projects and collaborating with others. 35 | 36 | ### Creating the Repository 🏗️ 37 | 38 | To kick off your Git journey, we've outlined the steps we took to create this repository. Follow along, and by the end, you'll have a solid understanding of the initial setup. 39 | 40 | + **Step 1:** Create an empty repository on [GitHub](https://github.com/new). 41 | + **Step 2:** Copy and execute the provided Git commands in your command line. 🖥️ 42 | ```bash 43 | echo "# git-and-github" >> README.md 44 | git init 45 | git add README.md 46 | git commit -m "first commit" 47 | git branch -M main 48 | git remote add origin https://github.com/PugazharasanC/git-and-github.git 49 | git push -u origin main 50 | ``` 51 | **Note for New Users:** 52 | 53 | > Before making any commits, ensure you have configured your user details using the provided Git commands under ["User Configuration."](#user-configuration) This is essential for accurate version control. Happy coding with Git! 🚀 54 | 55 | ## Command Breakdown 🛠️ 56 | 57 | 1. **`echo "# git-and-github" >> README.md`** 📢 58 | - Creates a [README.md](#learning-markdown-) file with the content "# git-and-github." 59 | 60 | 2. [**`git init`**](#git-init-) 🏁 61 | - Initializes a local Git repository, creating a hidden `.git` folder. 62 | 63 | 3. [**`git add README.md`**](#git-add-) ➕ 64 | - Adds the README.md file to the staging area. 65 | 66 | 4. [**`git commit -m "first commit"`**](#git-commit-) 📝 67 | - Commits the changes with the message "first commit." 68 | 69 | 5. [**`git branch -M main`**](#git-branch-) 🌿 70 | - Renames the default branch to 'main.' 71 | 72 | 6. [**`git remote add origin https://github.com/PugazharasanC/git-and-github.git`**](#git-remote-) 🌐 73 | - Adds the remote repository named 'origin.' 74 | 75 | 7. [**`git push -u origin main`**](#git-push-) 🚀 76 | - Pushes the local repository to the remote repository on GitHub, setting 'main' as the default branch. 77 | 78 | Feel free to execute these commands in your command line interface to initialize your Git and GitHub repositories. 79 | 80 | # Understanding Git Workflow 🌐 81 | 82 | In this section, let's explore the Git workflow and how changes move through different stages. 83 | 84 | ## Git Workflow Overview 🔄 85 | ``` 86 | 87 | Working Folder Staging Area Local Git Repository Remote Repository 88 | +----------------+ +----------------+ +-------------------+ +-------------------+ 89 | | | | | | | | | 90 | | | | | | | | | 91 | | Your Files | git add | Staged | git commit | Local Commits | git push | Remote Commits | 92 | | | --------> | Changes | -----------> | | ----------> | | 93 | | | | | | | | | 94 | +----------------+ +----------------+ +-------------------+ +-------------------+ 95 | ``` 96 | 97 | The diagram above illustrates the flow of changes from the working folder to the staging area and the local Git repository. 98 | 99 | ## Git Init 🏁 100 | 101 | The `git init` command is used to initialize a local Git repository, creating a hidden `.git` folder. 102 | 103 | To initialize a repository, simply run: 104 | 105 | ```bash 106 | git init 107 | ``` 108 | 109 | ## Git Add ➕ 110 | 111 | The `git add` command is essential for preparing changes to be committed. Here are two common use cases: 112 | 113 | + **`git add `** 114 | - Use this command to add a specific file to the staging area. 115 | 116 | + **`git add .`** 117 | - Employ this command to add all files in the current directory to the staging area. 118 | 119 | Select the appropriate `git add` variation based on your needs to stage changes effectively before committing. Happy staging! 🌟 120 | 121 | ## Git Commit 📝 122 | 123 | Committing changes is a crucial step in version control. Here are some useful Git commit commands: 124 | 125 | - **`git commit -m ""`** 126 | - Commit changes with a specified message. 127 | 128 | - **`git commit -a -m ""`** 129 | - Commit changes with a message and add all files to the staging area. 130 | - This is a shortcut to combine staging and committing for modified files. 131 | 132 | - **`git commit -am ""`** 133 | - Another shortcut to commit changes with a message and add all files to the staging area. 134 | - A concise way to streamline the commit process for modified files. 135 | 136 | These commands help you effectively record and save changes in your Git repository. Choose the one that fits your workflow! 🚀 137 | 138 | 139 | ## Git Branch 🌿 140 | 141 | The `git branch` command is a powerful tool for managing branches in your Git repository. Here are some essential use cases: 142 | 143 | + **`git branch `** 144 | - Create a new branch with the specified name. 145 | 146 | + **`git branch -M `** 147 | - Rename the current branch to the specified name. 148 | 149 | + **`git branch -d `** 150 | - Delete a branch. Use caution, as this permanently removes the branch. 151 | 152 | + **`git branch -m `** 153 | - Rename a branch from the old name to the new name. 154 | 155 | + **`git branch`** 156 | - List all the branches in the local repository. 157 | 158 | + **`git branch -r`** 159 | - List all the remote branches in the local repository. 160 | 161 | + **`git branch -a`** 162 | - List all branches in both the local and remote repositories. 163 | 164 | + **`git branch -v`** 165 | - List all branches in both the local and remote repositories with commit counts. 166 | 167 | These commands provide comprehensive branch management capabilities. Choose the right one based on your specific needs. Happy branching! 🌿 168 | 169 | ## Git Remote 🌐 170 | 171 | The `git remote` command facilitates interaction with remote repositories. Here are some essential use cases: 172 | 173 | + **`git remote add `** 174 | - Add a new remote repository with the specified name and URL. 175 | 176 | + **`git remote -v`** 177 | - List all remote repositories along with their URLs. 178 | 179 | + **`git remote rm `** 180 | - Remove a remote repository. Exercise caution, as this is irreversible. 181 | 182 | + **`git remote rename `** 183 | - Rename a remote repository from the old name to the new name. 184 | 185 | + **`git remote set-url `** 186 | - Change the URL of an existing remote repository. 187 | 188 | Utilize these commands to manage your interactions with remote repositories effectively. Happy collaborating! 🌐 189 | 190 | ## Git Push 🚀 191 | 192 | The `git push` command is vital for publishing your local changes to a remote repository on GitHub. Here are some useful variations: 193 | 194 | + **`git push`** 195 | - Push the local repository to the remote repository on GitHub and set the default branch to the current branch. 196 | 197 | + **`git push `** 198 | - Push the local repository to the remote repository on GitHub for the specified branch. 199 | 200 | + **`git push -u `** 201 | - Push the local repository to the remote repository on GitHub and set the default branch to the specified branch. 202 | 203 | + **`git push --set-upstream origin `** 204 | - Push the local repository to the remote repository on GitHub and set the default branch to the specified branch. 205 | 206 | + **`git push --all`** 207 | - Push all branches to the remote repository on GitHub. 208 | 209 | Utilize these commands based on your requirements to seamlessly update your remote repository. Happy pushing! 🚀 210 | 211 | ## Git Pull 🔄 212 | 213 | The `git pull` command is essential for incorporating changes from a remote repository into your local repository. Here are some variations: 214 | 215 | + **`git pull`** 216 | - Pull the remote repository and set the default branch to the current branch. 217 | 218 | + **`git pull `** 219 | - Pull the remote repository for the specified branch. 220 | 221 | + **`git pull --all`** 222 | - Pull changes from all branches in the remote repository. 223 | 224 | Choose the appropriate `git pull` command based on your workflow to keep your local repository up to date. Happy syncing! 🔄 225 | 226 | ## Git Checkout 🌿 227 | 228 | The `git checkout` command is versatile for navigating branches in your Git repository. Here are some variations: 229 | 230 | + **`git checkout `** 231 | - Switch to the specified branch. 232 | 233 | + **`git checkout -b `** 234 | - Create a new branch and switch to it. 235 | 236 | + **`git checkout -`** 237 | - Switch to the previous branch. This is useful for toggling between two branches. 238 | 239 | + **`git checkout -`** 240 | - Apologies for the confusion, but there's no direct command to switch to the next branch using `git checkout`. To navigate to the next branch, you can use the following: 241 | 242 | ```bash 243 | git checkout - 244 | ``` 245 | 246 | This command will toggle between the current and previous branches, effectively moving back and forth. 247 | 248 | Utilize these commands to seamlessly switch between branches in your Git workflow. Happy branching! 🌿 249 | 250 | ## Git Clean 🧹 251 | 252 | The `git clean` command is used to remove untracked files and directories from your local repository. Here are some variations: 253 | 254 | + **`git clean -f`** 255 | - Remove untracked files. 256 | 257 | + **`git clean -f -d`** 258 | - Remove untracked files and directories. 259 | 260 | + **`git clean -f -x`** 261 | - Remove untracked files and directories that are ignored by Git. 262 | 263 | + **`git clean -f -x -d`** 264 | - Remove untracked files, directories, and files that are ignored by Git. 265 | 266 | + **`git clean -f -x -e `** 267 | - Remove untracked files, directories, and files that are ignored by Git, except for the specified file. 268 | 269 | + **`git clean -f -x -e -n`** 270 | - Display the files that would be removed, but do not remove them from the local repository. 271 | 272 | Ensure caution when using these commands, especially with the `-f` flag, as it forcefully removes files. Double-check the files to be removed before executing. Happy cleaning! 🧹 273 | 274 | 275 | ## Basic Git Commands 💻 276 | 277 | Here's a compilation of essential Git commands for your everyday workflow. These commands cover a range of tasks, from checking Git's version to cloning repositories. 278 | 279 | + **`git --version`** 280 | - Check the version of Git. 281 | 282 | + **`git status`** 283 | - Check the status of the local repository. 284 | 285 | + **`git diff`** 286 | - Check the difference between the local repository and the remote repository. 287 | 288 | + **`git fetch `** 289 | - Fetch updates from the remote repository. 290 | 291 | + **`git pull `** 292 | - Pull changes from the remote repository for the specified branch. 293 | 294 | + **`git pull origin `** 295 | - An alternative syntax to pull changes from the specified branch on the remote repository. 296 | 297 | + **`git clone `** 298 | - Clone the remote repository into the local directory. 299 | 300 | + **`git clone -b `** 301 | - Clone the remote repository into the local directory and switch to the specified branch. 302 | 303 | + **`git log`** 304 | - View the commit history. 305 | 306 | + **`git show `** 307 | - Display the details of a specific commit. 308 | 309 | + **`git remote -v`** 310 | - List all remote repositories along with their URLs. 311 | 312 | + **`git branch -a`** 313 | - List all branches in both the local and remote repositories. 314 | 315 | + **`git branch -v`** 316 | - List all branches with commit counts. 317 | 318 | These commands provide a solid foundation for your Git journey. Explore and use them based on your version control needs. Happy coding! 🚀 319 | 320 | 321 | ## User Configuration 👤 322 | 323 | For Git beginners, configuring your user details is a crucial step. Here's a simple guide to get you started: 324 | 325 | + **`git config --global --list`** 326 | - List all global user configurations. 327 | 328 | + **`git config --global user.name ""`** 329 | - Set your global username. 330 | 331 | + **`git config --global user.email ""`** 332 | - Set your global email. 333 | 334 | + **`git config --global user.name`** 335 | - Check your global username. 336 | 337 | + **`git config --global user.email`** 338 | - Check your global email. 339 | 340 | These commands help personalize your Git experience and associate your commits with the correct user details. Happy configuring! 👤 341 | 342 | 343 | ## Git Ignore 🚫 344 | 345 | If you have files you don't want Git to track, using a `.gitignore` file is the solution. Here's a comprehensive guide to help you set it up: 346 | 347 | 1. **Create a `.gitignore` File:** 348 | - In the root directory of your Git repository, create a file named `.gitignore`. 349 | 350 | 2. **Edit the `.gitignore` File:** 351 | - Open the `.gitignore` file in a text editor. 352 | - Add the names of files, directories, or patterns you want Git to ignore. Each entry should be on a new line. 353 | 354 | For example, a basic `.gitignore` file might look like this: 355 | 356 | ```plaintext 357 | # Ignore compiled files 358 | *.class 359 | 360 | # Ignore log files 361 | *.log 362 | 363 | # Ignore build directories 364 | target/ 365 | ``` 366 | 367 | 3. **Save and Commit:** 368 | - Save the `.gitignore` file. 369 | - Commit the `.gitignore` file to your repository. 370 | 371 | This ensures that Git excludes specified files and directories from version control, maintaining a clean and focused repository. Happy coding! 🧹🚀 372 | 373 | 374 | Certainly! Let's add symbols to the necessary places: 375 | 376 | # Learning Markdown 📝 377 | 378 | Effectively documenting your projects requires a grasp of Markdown. Here are resources to help you get started: 379 | 380 | + **[Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)** 381 | - A comprehensive guide to Markdown syntax. 📚 382 | 383 | + **[Markdown Tutorial](https://www.markdowntutorial.com/)** 384 | - An interactive tutorial for hands-on learning. 🤓 385 | 386 | + **[Markdown Guide](https://www.markdownguide.org/)** 387 | - A detailed guide to mastering Markdown. 📘 388 | 389 | Feel free to explore these resources at your own pace and enhance your Markdown skills. Happy coding and documenting! 📝 390 | 391 | --- 392 | 393 | Congratulations on setting up your Git repository and exploring essential commands! 🎉 You've taken the first steps toward efficient version control and collaboration. Remember, Git is a powerful tool with endless possibilities, so keep exploring and refining your skills. 394 | 395 | As you embark on your coding journey, here are a few parting words of wisdom: 396 | 397 | - **Commit Often, Commit Wisely:** Regular, well-documented commits make it easier to track changes and collaborate seamlessly. 🔄 398 | 399 | - **Branch Strategically:** Branching allows you to work on features or fixes without affecting the main codebase. Choose your branching strategy wisely. 🌿 400 | 401 | - **Read the Docs:** Git has a rich set of features. Dive into the documentation whenever you need clarity or want to explore advanced functionalities. 📖 402 | 403 | - **Collaborate and Learn:** Git is a collaborative tool. Engage with the Git community, learn from others, and share your experiences. 🤝 404 | 405 | Feel the Git flow, enjoy the coding journey, and may your repositories always be green! 🌱 Happy coding! 🚀 --------------------------------------------------------------------------------