{"id":13492433,"url":"https://github.com/msaaddev/git-commands-workflows","last_synced_at":"2025-04-15T09:41:02.596Z","repository":{"id":53922769,"uuid":"356589251","full_name":"msaaddev/git-commands-workflows","owner":"msaaddev","description":"🚀 All the git commands and workflows you need to know","archived":false,"fork":false,"pushed_at":"2021-07-23T13:42:33.000Z","size":156,"stargazers_count":65,"open_issues_count":0,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T05:26:37.728Z","etag":null,"topics":["bash-script","cheatsheet","command-line","commands","commands-cheat-sheet","commands-git","git","git-bash","git-basic-command","git-commands","git-commit","git-push","git-sync","git-workflow","git-workflows","github","shell","shellscript","workflow"],"latest_commit_sha":null,"homepage":"https://twitter.com/msaaddev","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msaaddev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-10T13:25:31.000Z","updated_at":"2025-02-16T14:23:14.000Z","dependencies_parsed_at":"2022-08-13T04:30:31.660Z","dependency_job_id":null,"html_url":"https://github.com/msaaddev/git-commands-workflows","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msaaddev%2Fgit-commands-workflows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msaaddev%2Fgit-commands-workflows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msaaddev%2Fgit-commands-workflows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msaaddev%2Fgit-commands-workflows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msaaddev","download_url":"https://codeload.github.com/msaaddev/git-commands-workflows/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249045382,"owners_count":21203865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash-script","cheatsheet","command-line","commands","commands-cheat-sheet","commands-git","git","git-bash","git-basic-command","git-commands","git-commit","git-push","git-sync","git-workflow","git-workflows","github","shell","shellscript","workflow"],"created_at":"2024-07-31T19:01:05.975Z","updated_at":"2025-04-15T09:41:02.534Z","avatar_url":"https://github.com/msaaddev.png","language":"Shell","readme":"![git-commands-workflows](images/cover.jpg)\n\n*The git commands \u0026 workflows you need to know to work with git and automate your regular commands.*\n\n\u003cbr /\u003e\n\n\u003cimg src=\"./images/suitcase.png\" width=\"10%\" /\u003e\n\n## Initialization\n\n```sh\n# paste this in your terminal to change your current working directory to the project directory\ncd your_project_path\n\n# initialize git\ngit init\n```\n\n\u003cbr /\u003e\n\n\u003cimg src=\"./images/rocket.png\" width=\"10%\" /\u003e\n\n## Commands\n\n⚡️ The **repetitive** commands that I (and everyone else) use regularly.\n\n```sh\n\n# connect the remote GitHub repo with your local project\ngit remote add origin [github-repo-url]\n\n# see untracked files\ngit status\n\n# add all untracked files to the staging area\ngit add .\n\n# commit the tracked files of the staging area\ngit commit -m \"commit-msg\"\n\n# push all the changes to the GitHub\ngit push -u origin master\n\n```\n\n🏗 **Git Setup** if you have never used git before.\n\n```sh\n# configure git with your github username\ngit config --global user.name \"your_github_username\"\n\n# configure git with your github email (email you used to sign up on GitHub)\ngit config --global user.email \"your_email@whatever.com\"\n```\n\n🎩 **Clone** a repository in your computer.\n\n```sh\n# clone a repo\ngit clone [repo_url]\n```\n\n🌲 The git commands you need to know to *work* with **branches**.\n\n```sh\n\n# list all branches\ngit branch\n\n# create a new branch\ngit branch [branch_name]\n\n# checkout to the new branch\ngit checkout [branch_name]\n\n# \tOR\n\n# create AND checkout to the new branch\ngit checkout -b [branch_name]\n\n# pushing the new branch on GitHub\ngit push origin [branch_name]\n\n# delete a branch locally\ngit branch -d [branch_name]\n\n# delete a branch on GitHub\ngit push origin -d [branch_name]\n\n# pulling changes from some other branch\ngit pull origin [branch_name]\n\n# merge a branch with the current active branch\ngit merge [branch_name]\n\n# merge a branch to some defined branch\ngit merge [source_branch] [target_branch]\n\n```\n\n📚 **Stashing** untracked changes — It saves all the *new untracked changes* and rewind your repo to the last commit.\n\n```sh\n\n# stash the untracked changes\ngit stash\n\n# pop an existing stack\ngit stash apply stash@{stash_number}\n\n# list all stashes\ngit stash list\n\n# delete all saved stashes\ngit stash clear\n\n```\n\n🍒 **Pulling** all the new changes from the remote repository on GitHub\n\n```sh\n\n# pull changes from master branch\ngit pull origin master\n\n# pulling changes from some other branch\ngit pull origin [branch_name]\n\n```\n\n🎯 Keep your GitHub forked repo in **sync** with the original repository.\n\n```sh\n\n# STEP #1: show URLs of remote repositories when listing your current remote connections\ngit remote -v\n\n# STEP #2: add upstream\ngit remote add upstream [source-repo-url]\n\n# STEP #3: fetching all the new changes from the main repository\ngit fetch upstream\n\n# STEP #4: merging the new changes from the original repo to your forked local repo\ngit merge upstream/master\n\n# STEP #5: pushing the new changes of the forked local repo to the GitHub\ngit push origin master\n\n```\n\n` Note: ` Replace master with main if your primary branch is `main`.\n\n\n\u003cbr/\u003e\n\n\u003cimg src=\"./images/workflow.png\" width=\"10%\" /\u003e\n\n## Workflows\n\nOpen your `.zshrc` or `.bashrc` file. It is located in your Home directory. Paste the following shellcode there.\n\n```sh\n\n# Keep your GitHub forked repo in sync with the original repository with master as the primary branch\nfunction fetchremotems() {\n\tgit fetch upstream \u0026\u0026\n\tgit merge upstream/master \u0026\u0026\n\tgit push origin master\n}\n\n# Keep your GitHub forked repo in sync with the original repository with main as the primary branch\nfunction fetchremotemn() {\n\tgit fetch upstream \u0026\u0026\n\tgit merge upstream/main \u0026\u0026\n\tgit push origin main\n}\n\n# create new branch and checkout to it\nfunction gcb() {\n\tgit checkout -b \"${1}\"\n}\n\n# checkout to a branch\nfunction gch() {\n\tgit checkout \"${1}\"\n}\n\n# push changes to another branch\nfunction gbp() {\n\tgit push origin \"${1}\"\n}\n\n# add, commit, push changes to github\nfunction gacp() {\n\tgit add . \u0026\u0026\n\tgit commit -m \"${1}\" \u0026\u0026\n\tgit push\n}\n\n# aliases\nalias gi='git init'\nalias gs='git status'\nalias ga='git add '\nalias gaa='git add .'\nalias gc='git commit -m '\nalias gp='git push'\nalias gra='git remote add origin '\nalias gpm='git push -u origin master'\n\n# create YOUR own git workflows\nfunction [functionName]() {\n    # commands to execute when function is called\n    # if there are more than one commands, use \u0026\u0026 between them\n    # to use the first output from the terminal, use \"${1}\"\n}\n\n\n```\n\n### 🚀 Usage\n\nFetching changes from the original repo to your forked repo.\n\n```sh\n\ncd your_project_path\n\n# do this only once in every forked local repo to add upstream\ngit remote add upstream [source-repo-url]\n\n# write the following in the terminal – primary branch: master – whenever you need to fetch the changes\nfetchremotems\n\n# write the following in the terminal – primary branch: main – whenever you need to fetch the changes\nfetchremotemn\n\n```\n\nUsage of the rest of the workflows.\n\n```sh\n\n# To create a new branch and also to checkout to it\ngcb [branch_name]\n\n# To checkout to an existing branch\ngch [branch_name]\n\n# To push changes to another branch\ngbp [branch_name]\n\n# To add, commit and push changes to the github\ngacp \"commit-msg\"\n\n# initialize git\ngi\n\n# check status\ngs\n\n# stage untracked file\nga [file_name]\n\n# stage all untracked files\ngaa\n\n# commit the changes\ngc \"commit-msg\"\n\n# connect remote repo to the local repo\ngra [repo-link]\n\n# push changes to master\ngpm\n\n```\n\n## 👨🏻‍💻 Contributing\n\nFeel 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.\n\n## ⚡️ Other Projects\n\nI 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.\n\n## 🔑 License \u0026 Conduct\n\n- MIT © [Saad Irfan](https://github.com/msaaddev)\n- [Code of Conduct](https://github.com/msaaddev/git-commands-workflows/blob/master/code-of-conduct.md)\n","funding_links":[],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsaaddev%2Fgit-commands-workflows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsaaddev%2Fgit-commands-workflows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsaaddev%2Fgit-commands-workflows/lists"}