├── .bashrc ├── .gitattributes ├── .gitignore ├── .zshrc ├── LICENSE ├── code-of-conduct.md ├── contributing.md ├── images ├── cover.jpg ├── rocket.png ├── suitcase.png └── workflow.png └── readme.md /.bashrc: -------------------------------------------------------------------------------- 1 | # ---------------- git worflows ---------------- # 2 | 3 | # Keep your GitHub forked repo in sync with the original repository with master as the primary branch 4 | function fetchremotems() { 5 | git fetch upstream && 6 | git merge upstream/master && 7 | git push origin master 8 | } 9 | 10 | # Keep your GitHub forked repo in sync with the original repository with main as the primary branch 11 | function fetchremotemn() { 12 | git fetch upstream && 13 | git merge upstream/main && 14 | git push origin main 15 | } 16 | 17 | # create new branch and checkout to it 18 | function gcb() { 19 | git checkout -b "${1}" 20 | } 21 | 22 | # checkout to a branch 23 | function gc() { 24 | git checkout "${1}" 25 | } 26 | 27 | # push changes to another branch 28 | function gbp() { 29 | git push origin "${1}" 30 | } 31 | 32 | # add, commit, push changes to github 33 | function gacp() { 34 | git add . && 35 | git commit -m "${1}" && 36 | git push 37 | } 38 | 39 | # aliases 40 | alias gi='git init' 41 | alias gs='git status' 42 | alias gaa='git add .' 43 | alias gc='git commit -m ' 44 | alias gp='git push' 45 | alias gpm='git push origin master' 46 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # NPM # 2 | ########## 3 | # Ignore all directories called node_modules in current folder and any subfolders. 4 | node_modules/ 5 | /node_modules/ 6 | 7 | # Packages # 8 | ############ 9 | *.7z 10 | *.dmg 11 | *.gz 12 | *.bz2 13 | *.iso 14 | *.jar 15 | *.rar 16 | *.tar 17 | *.zip 18 | *.tgz 19 | *.map 20 | 21 | # Logs and databases # 22 | ###################### 23 | *.log 24 | *.sql 25 | *.env 26 | 27 | # OS generated files # 28 | ###################### 29 | **.DS_Store* 30 | ehthumbs.db 31 | Icon? 32 | Thumbs.db 33 | ._* 34 | 35 | # Vim generated files # 36 | ###################### 37 | *.un~ 38 | 39 | # SASS # 40 | ########## 41 | **/.sass-cache 42 | **/.sass-cache/* 43 | **/.map 44 | 45 | # Composer # 46 | ########## 47 | !assets/js/vendor/ 48 | wpcs/ 49 | /vendor/ 50 | 51 | # Bower # 52 | ########## 53 | assets/bower_components/* 54 | 55 | # Codekit # 56 | ########## 57 | /codekit-config.json 58 | *.codekit 59 | **.codekit-cache/* 60 | 61 | # Compiled Files and Build Dirs # 62 | ########## 63 | /README.html 64 | 65 | # PhpStrom Project Files # 66 | .idea/ 67 | library/vendors/composer 68 | assets/img/.DS_Store 69 | 70 | # Visual Studio Project Files # 71 | .vs/ 72 | 73 | # No lock files. 74 | package-lock.json 75 | yarn.lock 76 | settings.dat 77 | -------------------------------------------------------------------------------- /.zshrc: -------------------------------------------------------------------------------- 1 | # ---------------- git worflows ---------------- # 2 | 3 | # Keep your GitHub forked repo in sync with the original repository with master as the primary branch 4 | function fetchremotems() { 5 | git fetch upstream && 6 | git merge upstream/master && 7 | git push origin master 8 | } 9 | 10 | # Keep your GitHub forked repo in sync with the original repository with main as the primary branch 11 | function fetchremotemn() { 12 | git fetch upstream && 13 | git merge upstream/main && 14 | git push origin main 15 | } 16 | 17 | # create new branch and checkout to it 18 | function gcb() { 19 | git checkout -b "${1}" 20 | } 21 | 22 | # checkout to a branch 23 | function gc() { 24 | git checkout "${1}" 25 | } 26 | 27 | # push changes to another branch 28 | function gbp() { 29 | git push origin "${1}" 30 | } 31 | 32 | # add, commit, push changes to github 33 | function gacp() { 34 | git add . && 35 | git commit -m "${1}" && 36 | git push 37 | } 38 | 39 | # aliases 40 | alias gi='git init' 41 | alias gs='git status' 42 | alias gaa='git add .' 43 | alias gc='git commit -m ' 44 | alias gp='git push' 45 | alias gpm='git push origin master' 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2021 msaaddev 2 | 3 | Permission is hereby granted, free of 4 | charge, to any person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to the 9 | following conditions: 10 | 11 | The above copyright notice and this permission notice 12 | (including the next paragraph) shall be included in all copies or substantial 13 | portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 18 | EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | mrsaadirfan@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | 1. Open the issue first. 4 | 2. Fork the repository. 5 | 3. Create and switch to the new branch. New branch name convention must be like this yourUsername/newFeature, for instance, `msaaddev/pr-review` 6 | 4. Commit the changes in your forked repository. 7 | 5. Open a pull request & mention the issue number in the pull request for reference. 8 | -------------------------------------------------------------------------------- /images/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msaaddev/git-commands-workflows/1cc166c1fdd85fd1d07cadc826d53fadb4ff9284/images/cover.jpg -------------------------------------------------------------------------------- /images/rocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msaaddev/git-commands-workflows/1cc166c1fdd85fd1d07cadc826d53fadb4ff9284/images/rocket.png -------------------------------------------------------------------------------- /images/suitcase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msaaddev/git-commands-workflows/1cc166c1fdd85fd1d07cadc826d53fadb4ff9284/images/suitcase.png -------------------------------------------------------------------------------- /images/workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msaaddev/git-commands-workflows/1cc166c1fdd85fd1d07cadc826d53fadb4ff9284/images/workflow.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ![git-commands-workflows](images/cover.jpg) 2 | 3 | *The git commands & workflows you need to know to work with git and automate your regular commands.* 4 | 5 |
6 | 7 | 8 | 9 | ## Initialization 10 | 11 | ```sh 12 | # paste this in your terminal to change your current working directory to the project directory 13 | cd your_project_path 14 | 15 | # initialize git 16 | git init 17 | ``` 18 | 19 |
20 | 21 | 22 | 23 | ## Commands 24 | 25 | ⚡️ The **repetitive** commands that I (and everyone else) use regularly. 26 | 27 | ```sh 28 | 29 | # connect the remote GitHub repo with your local project 30 | git remote add origin [github-repo-url] 31 | 32 | # see untracked files 33 | git status 34 | 35 | # add all untracked files to the staging area 36 | git add . 37 | 38 | # commit the tracked files of the staging area 39 | git commit -m "commit-msg" 40 | 41 | # push all the changes to the GitHub 42 | git push -u origin master 43 | 44 | ``` 45 | 46 | 🏗 **Git Setup** if you have never used git before. 47 | 48 | ```sh 49 | # configure git with your github username 50 | git config --global user.name "your_github_username" 51 | 52 | # configure git with your github email (email you used to sign up on GitHub) 53 | git config --global user.email "your_email@whatever.com" 54 | ``` 55 | 56 | 🎩 **Clone** a repository in your computer. 57 | 58 | ```sh 59 | # clone a repo 60 | git clone [repo_url] 61 | ``` 62 | 63 | 🌲 The git commands you need to know to *work* with **branches**. 64 | 65 | ```sh 66 | 67 | # list all branches 68 | git branch 69 | 70 | # create a new branch 71 | git branch [branch_name] 72 | 73 | # checkout to the new branch 74 | git checkout [branch_name] 75 | 76 | # OR 77 | 78 | # create AND checkout to the new branch 79 | git checkout -b [branch_name] 80 | 81 | # pushing the new branch on GitHub 82 | git push origin [branch_name] 83 | 84 | # delete a branch locally 85 | git branch -d [branch_name] 86 | 87 | # delete a branch on GitHub 88 | git push origin -d [branch_name] 89 | 90 | # pulling changes from some other branch 91 | git pull origin [branch_name] 92 | 93 | # merge a branch with the current active branch 94 | git merge [branch_name] 95 | 96 | # merge a branch to some defined branch 97 | git merge [source_branch] [target_branch] 98 | 99 | ``` 100 | 101 | 📚 **Stashing** untracked changes — It saves all the *new untracked changes* and rewind your repo to the last commit. 102 | 103 | ```sh 104 | 105 | # stash the untracked changes 106 | git stash 107 | 108 | # pop an existing stack 109 | git stash apply stash@{stash_number} 110 | 111 | # list all stashes 112 | git stash list 113 | 114 | # delete all saved stashes 115 | git stash clear 116 | 117 | ``` 118 | 119 | 🍒 **Pulling** all the new changes from the remote repository on GitHub 120 | 121 | ```sh 122 | 123 | # pull changes from master branch 124 | git pull origin master 125 | 126 | # pulling changes from some other branch 127 | git pull origin [branch_name] 128 | 129 | ``` 130 | 131 | 🎯 Keep your GitHub forked repo in **sync** with the original repository. 132 | 133 | ```sh 134 | 135 | # STEP #1: show URLs of remote repositories when listing your current remote connections 136 | git remote -v 137 | 138 | # STEP #2: add upstream 139 | git remote add upstream [source-repo-url] 140 | 141 | # STEP #3: fetching all the new changes from the main repository 142 | git fetch upstream 143 | 144 | # STEP #4: merging the new changes from the original repo to your forked local repo 145 | git merge upstream/master 146 | 147 | # STEP #5: pushing the new changes of the forked local repo to the GitHub 148 | git push origin master 149 | 150 | ``` 151 | 152 | ` Note: ` Replace master with main if your primary branch is `main`. 153 | 154 | 155 |
156 | 157 | 158 | 159 | ## Workflows 160 | 161 | Open your `.zshrc` or `.bashrc` file. It is located in your Home directory. Paste the following shellcode there. 162 | 163 | ```sh 164 | 165 | # Keep your GitHub forked repo in sync with the original repository with master as the primary branch 166 | function fetchremotems() { 167 | git fetch upstream && 168 | git merge upstream/master && 169 | git push origin master 170 | } 171 | 172 | # Keep your GitHub forked repo in sync with the original repository with main as the primary branch 173 | function fetchremotemn() { 174 | git fetch upstream && 175 | git merge upstream/main && 176 | git push origin main 177 | } 178 | 179 | # create new branch and checkout to it 180 | function gcb() { 181 | git checkout -b "${1}" 182 | } 183 | 184 | # checkout to a branch 185 | function gch() { 186 | git checkout "${1}" 187 | } 188 | 189 | # push changes to another branch 190 | function gbp() { 191 | git push origin "${1}" 192 | } 193 | 194 | # add, commit, push changes to github 195 | function gacp() { 196 | git add . && 197 | git commit -m "${1}" && 198 | git push 199 | } 200 | 201 | # aliases 202 | alias gi='git init' 203 | alias gs='git status' 204 | alias ga='git add ' 205 | alias gaa='git add .' 206 | alias gc='git commit -m ' 207 | alias gp='git push' 208 | alias gra='git remote add origin ' 209 | alias gpm='git push -u origin master' 210 | 211 | # create YOUR own git workflows 212 | function [functionName]() { 213 | # commands to execute when function is called 214 | # if there are more than one commands, use && between them 215 | # to use the first output from the terminal, use "${1}" 216 | } 217 | 218 | 219 | ``` 220 | 221 | ### 🚀 Usage 222 | 223 | Fetching changes from the original repo to your forked repo. 224 | 225 | ```sh 226 | 227 | cd your_project_path 228 | 229 | # do this only once in every forked local repo to add upstream 230 | git remote add upstream [source-repo-url] 231 | 232 | # write the following in the terminal – primary branch: master – whenever you need to fetch the changes 233 | fetchremotems 234 | 235 | # write the following in the terminal – primary branch: main – whenever you need to fetch the changes 236 | fetchremotemn 237 | 238 | ``` 239 | 240 | Usage of the rest of the workflows. 241 | 242 | ```sh 243 | 244 | # To create a new branch and also to checkout to it 245 | gcb [branch_name] 246 | 247 | # To checkout to an existing branch 248 | gch [branch_name] 249 | 250 | # To push changes to another branch 251 | gbp [branch_name] 252 | 253 | # To add, commit and push changes to the github 254 | gacp "commit-msg" 255 | 256 | # initialize git 257 | gi 258 | 259 | # check status 260 | gs 261 | 262 | # stage untracked file 263 | ga [file_name] 264 | 265 | # stage all untracked files 266 | gaa 267 | 268 | # commit the changes 269 | gc "commit-msg" 270 | 271 | # connect remote repo to the local repo 272 | gra [repo-link] 273 | 274 | # push changes to master 275 | gpm 276 | 277 | ``` 278 | 279 | ## 👨🏻‍💻 Contributing 280 | 281 | Feel free to add your git workflows in the repository. Just make sure you first read the [contributing guidelines](https://github.com/msaaddev/git-commands-workflows/blob/master/contributing.md) before making a PR. 282 | 283 | ## ⚡️ Other Projects 284 | 285 | I have curated a [detailed list](https://github.com/msaaddev/open-source) of all the open-source projects I have authored. Do take out a moment and take a look. 286 | 287 | ## 🔑 License & Conduct 288 | 289 | - MIT © [Saad Irfan](https://github.com/msaaddev) 290 | - [Code of Conduct](https://github.com/msaaddev/git-commands-workflows/blob/master/code-of-conduct.md) 291 | --------------------------------------------------------------------------------