├── README.md ├── assets ├── 01_git_and_git_log_.jpeg ├── 02_git_pull.jpeg ├── 03_git_push.jpeg └── 04_merge_and_rebase.png └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # Git Basics 2 | 3 | ## Setup 4 | 5 | ```bash 6 | # Check git version 7 | git --version 8 | 9 | # Set username and email 10 | git config --global user.name "Your Name" 11 | git config --global user.email "youremail@mail.com" 12 | 13 | # Set default branch as main 14 | git config --global init.defaultBranch main 15 | 16 | # Set automatic command line colouring for git 17 | git config --global color.ui auto 18 | 19 | # List all global git config variables 20 | git config --list 21 | 22 | # ssh setup 23 | # Add id_ed25519.pub as ssh key on Github 24 | # Path in Linux : ~/.ssh/id_ed25519.pub 25 | # Path in Windows : /c/Users/you/.ssh/id_ed25519.pub 26 | ssh-keygen -t ed25519 -C "youremail@mail.com" 27 | 28 | # OR 29 | 30 | # Store credentials 31 | git config --global credential.helper store 32 | ``` 33 | 34 | ## Start 35 | 36 | ```bash 37 | # Create a local git repository 38 | cd [path] 39 | git init 40 | ``` 41 | 42 | ## Stage and Snapshot 43 | 44 | ```bash 45 | # Check the status of a repository. (View unstaged, staged and modified files) 46 | git status 47 | 48 | # Add a file from working area to staging area 49 | git add [path] 50 | 51 | # Create a snapshot of your staged changes 52 | git commit -m "[descriptive message]" 53 | 54 | # Change the commit message of last commit 55 | git commit --amend -m "[new message]" 56 | 57 | # Display the difference of what is changed but not staged 58 | git diff 59 | 60 | # Display the difference of what is staged but not commited 61 | git diff --staged 62 | 63 | # Unstage a file while retaining the changes in working directory 64 | git reset [file] 65 | ``` 66 | 67 | ## Branch & Merge 68 | 69 | ```bash 70 | # List your branches 71 | git branch 72 | 73 | # Create a new branch at the current commit 74 | git branch [branch_name] 75 | 76 | # Switch to another branch 77 | git checkout [branch_name] 78 | 79 | # Create and swtich to the branch 80 | git checkout -b [branch_name] 81 | 82 | # Merge the specified branch's history into the current one 83 | git merge [branch_name] 84 | 85 | # Show commit history of current branch 86 | git log 87 | ``` 88 | 89 | ## Remote repositories 90 | 91 | ```bash 92 | # Clone a remote repository 93 | git clone [url] 94 | 95 | # Fetch the meta-data of remote repository 96 | git fetch 97 | 98 | # Transmit local changes to remote repository 99 | git push 100 | 101 | # Fetch and merge any commits from the remote branch 102 | git pull 103 | ``` 104 | 105 | ## Rewrite history 106 | 107 | ```bash 108 | # Apply commits of current branch ahead of specified one 109 | git rebase [branch_name] 110 | 111 | # Reset to a specified commit and clear the staging area 112 | git reset --hard [commit] 113 | 114 | # Reset to a specified commit without clearing the staging area 115 | git reset --soft [commit] 116 | ``` 117 | 118 | ## Ignoring patterns 119 | 120 | ```bash 121 | # Add files that you want to ignore in .gitignore file 122 | *.txt 123 | node_modules 124 | ``` 125 | 126 | ## Temporary commits 127 | 128 | ```bash 129 | # Save modified and staged changes 130 | git stash 131 | 132 | # List stashes 133 | git stash list 134 | 135 | # Apply changes from top stash stack 136 | git stash apply 137 | 138 | # Drop changes from top stash stack 139 | git stash drop 140 | 141 | # Apply and drop from top stash stack 142 | git stash pop 143 | ``` 144 | 145 | --- 146 | 147 | ## Common Commit Message Types 148 | 1. **`feat:` (Feature):** 149 | - Indicates the addition of a new feature or significant enhancement. 150 | 151 | Example: 152 | ``` 153 | feat: Implement user authentication 154 | ``` 155 | 156 | 2. **`fix:` (Bug Fix):** 157 | - Signifies a bug fix or correction of an existing issue. 158 | 159 | Example: 160 | ``` 161 | fix: Resolve issue with login form validation 162 | ``` 163 | 164 | 3. **`chore:` (Chores/Tasks):** 165 | - Used for routine tasks, maintenance, or other non-feature-related changes. 166 | 167 | Example: 168 | ``` 169 | chore: Update build scripts 170 | ``` 171 | 172 | 4. **`docs:` (Documentation):** 173 | - Indicates changes or additions to documentation. 174 | 175 | Example: 176 | ``` 177 | docs: Update README with installation instructions 178 | ``` 179 | 180 | 5. **`style:` (Code Style):** 181 | - Used when only the formatting or coding style is changed, without affecting the code's logic. 182 | 183 | Example: 184 | ``` 185 | style: Format code according to style guide 186 | ``` 187 | 188 | 6. **`refactor:` (Code Refactoring):** 189 | - Signifies changes to the codebase that neither fix a bug nor add a feature but improve the code structure or design. 190 | 191 | Example: 192 | ``` 193 | refactor: Simplify error handling in user service 194 | ``` 195 | 196 | 7. **`test:` (Tests):** 197 | - Indicates changes or additions to tests. 198 | 199 | Example: 200 | ``` 201 | test: Add unit tests for authentication module 202 | ``` 203 | 204 | 8. **`build:` (Build System):** 205 | - Used for changes that affect the build system or external dependencies. 206 | 207 | Example: 208 | ``` 209 | build: Update npm packages to the latest version 210 | ``` 211 | 212 | 9. **`ci:` (Continuous Integration):** 213 | - Signifies changes to the configuration or scripts related to continuous integration. 214 | 215 | Example: 216 | ``` 217 | ci: Update Travis CI configuration 218 | ``` 219 | 220 | 10. **`perf:` (Performance):** 221 | - Indicates changes that improve the performance of the code. 222 | 223 | Example: 224 | ``` 225 | perf: Optimize database query for user retrieval 226 | ``` 227 | 228 | These prefixes help provide context and structure to your commit messages, making it easier for team members to understand the nature of changes in the project. The key is to adopt a convention that suits your team's workflow and stick to it consistently. 229 | 230 | --- 231 | 232 | # Extras 233 | 234 | ![01_git_and_git_log .jpeg](assets/01_git_and_git_log_.jpeg) 235 | 236 | ![02_git_pull.jpeg](assets/02_git_pull.jpeg) 237 | 238 | ![03_git_push.jpeg](assets/03_git_push.jpeg) 239 | 240 | ![04_merge_and_rebase.png](assets/04_merge_and_rebase.png) 241 | -------------------------------------------------------------------------------- /assets/01_git_and_git_log_.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDistroHopper/learn-git/24197e5675dbd3404e6924357b9232d1c4efe485/assets/01_git_and_git_log_.jpeg -------------------------------------------------------------------------------- /assets/02_git_pull.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDistroHopper/learn-git/24197e5675dbd3404e6924357b9232d1c4efe485/assets/02_git_pull.jpeg -------------------------------------------------------------------------------- /assets/03_git_push.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDistroHopper/learn-git/24197e5675dbd3404e6924357b9232d1c4efe485/assets/03_git_push.jpeg -------------------------------------------------------------------------------- /assets/04_merge_and_rebase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDistroHopper/learn-git/24197e5675dbd3404e6924357b9232d1c4efe485/assets/04_merge_and_rebase.png --------------------------------------------------------------------------------