{"id":20455220,"url":"https://github.com/pouyapouryaie/gitdemo","last_synced_at":"2025-10-13T03:38:42.083Z","repository":{"id":149312777,"uuid":"226081867","full_name":"PouyaPouryaie/gitdemo","owner":"PouyaPouryaie","description":"This repository provides a comprehensive guide to common Git commands, covering essential tasks for version control and collaboration.","archived":false,"fork":false,"pushed_at":"2025-06-22T19:49:02.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-29T07:50:47.395Z","etag":null,"topics":["git"],"latest_commit_sha":null,"homepage":"https://pouyapouryaie.github.io/gitdemo/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PouyaPouryaie.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-05T11:02:34.000Z","updated_at":"2025-06-22T19:40:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"d7de455f-87ca-459d-9ea3-61494b048bd6","html_url":"https://github.com/PouyaPouryaie/gitdemo","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/PouyaPouryaie/gitdemo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2Fgitdemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2Fgitdemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2Fgitdemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2Fgitdemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PouyaPouryaie","download_url":"https://codeload.github.com/PouyaPouryaie/gitdemo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2Fgitdemo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270040726,"owners_count":24516684,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["git"],"created_at":"2024-11-15T11:18:16.288Z","updated_at":"2025-10-13T03:38:37.048Z","avatar_url":"https://github.com/PouyaPouryaie.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Commands Tutorial\nThis repository provides a comprehensive guide to common Git commands, covering essential tasks for version control and collaboration.\n\n# Basic Commands:\n\n## Init\nCreating a new Git repository\n```bash\ngit init\n```\n\n## Clone\nCloning an existing repository\n```bash\ngit clone \u003crepository-url-address\u003e\n```\n\n## Add\nAdding files to the staging area\n```bash\ngit add \u003cfile-name\u003e or ('.' that means all files)\n```\n\n## Commit\nCommitting changes to the local repository\n\n- simple: `git commit -m \"commit message\"`\n- add \u0026 commit: `git commit -am \"commit message\"`(recommend for when you just modify file not added)\n- commit with issue done: `git commit -m \"commit message %close #issueNumber\"` (after that push to remote repo)\n- amend: adding latest changes to the previous commit: \n    `git commit --amend -m \"an updated commit message\"`\n\n## Status\nChecking the current status of the repository\n```bash\ngit status\n```\n## Log\nViewing the commit history\n- showing comprehensive log: `git log \u003coptions\u003e \u003crevision-range\u003e`\n- Showing compact log: `git log --oneline`\n- Showing logs in graph mode: `git log --graph`\n\n## Diff \u0026 Show\nComparing changes between commits\n\n- showing for a specific commit\n```bash\ngit show \u003ccommit_hash\u003e\n```\n- showing for a specific file\n```bash\ngit show file_name\n```\n- list of all changes\n```bash\ngit diff-tree -r \u003ccommit_hash\u003e\n```\n- compare two branch -\u003e In short, it will show you all the commits that “branch_2” has that are not in “branch_1”\n```bash\ngit diff \u003cbranch_1\u003e..\u003cbranch_2\u003e\n```\n\n# Branching and Merging\n\n## Branch\nCreating and listing branches\n\n- add new branch: `git branch -b \u003cbranch-name\u003e`\n- remove a branch: `git branch -d \u003cbranch-name\u003e`\n- remote a branch for origin: `git push origin -d \u003cbranch-name\u003e`\n- create main branch : `git branch -M main`\n- show list of branch: `git branch -a`\n\n## Checkout\nSwitching between branches\n```bash\ngit checkout \u003cbranch-name\u003e\n```\n\n## Merge\nMerging branches\n```bash\ngit merge \u003cbranch-name\u003e\n```\n- `--no-ff`: It provides a clear and explicit record in your Git history of when a feature branch (or any branch) was integrated into long-lived branches like `main`. (`git merge --no-ff \u003cbranch-name\u003e`)\n    - Clearer Feature Boundaries\n    - Easier Reverts\n\n## Rebase\nReordering commits on a branch\n\n- normal:\n```bash\ngit rebase \u003cbranch-name\u003e (all of commits in 'branch-name' rebase onto the current branch)\n```\n- interactive:\n```bash\ngit rebase -i \u003cbranch-name\u003e (then in the file you pick the order of commit then save the file)\ngit rebase -i HEAD~5 (this mean you can rearrange, the last 5 commits)\n    # option Commands:\n    # p, pick = use commit\n    # r, reword = use commit, but edit the commit message\n    # e, edit = use commit, but stop for amending\n    # s, squash = use commit, but meld into the previous commit\n    # f, fixup = like \"squash\", but discard this commit's log message\n    # x, exec = run command (the rest of the line) using shell\n    # d, drop = remove commit\n```\n- advance:\n```bash\ngit rebase --onto \u003cbranch-name-1\u003e \u003cbranch-name-2\u003e \u003cbranch-name-3\u003e (we order sequence of branch rebase in one history)\n```\n- conflict: first resolve the conflict and then tell Git to resolve the problem:\n```bash \ngit add \u003cfile-name\u003e\ngit commit m \u003ccommit-message\u003e\n# then\n# if you want update index: \ngit rebase --continue\n# if you skip update: \ngit rebase --skip\n# if you want undo rebase: \ngit rebase --abort\n```\n\n## Cherry pick\ngit cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD.\u003cbr\u003e Cherry picking is the act of picking a commit from a branch and applying it to another.\n- UseCases\n    - when a bug is dicovered through developing a new feature and you want to directly commit it to the `main`\n    - during team collaboration\n    - for merge confilict resolution\n        - steps:\n            - `git merge --abort`\n            - `git log dev` (to find the commit hash)\n            - `git cherry-pick \u003ccommit-hash\u003e`\n            - if you got error:\n                - fix the confilict\n                - `git add .` or `git add \u003cfile\u003e`\n                - `git commit -m \"commit message\"`\n\n```bash\ngit cherry-pick \u003ccommit-hash\u003e\n# Steps\n1. Find hash-key from `git log`\n2. Checkout to the main branch\n3. Use cherry-pick command to pick and commit it to main branch\n```\n- Options\n    - `--edit`: will cause git to prompt for a commit message before applying the cherry-pick operation\n    - `--no-commit`: will execute the cherry pick but instead of making a new commit it will move the contents of the target commit into the working directory of the current branch.\n    - `--signoff`: will add a 'signoff' signature line to the end of the cherry-pick commit message\n\n\n# Remote Repositories\n\n## Remote\nAdding and listing remote repositories\n- adding remote repository url: `git remote add origin \u003cremote-url-address\u003e`\n- checking remote url:`git remote -v`  \n\n## Push\nPushing commits to a remote repository\n\n- basic command: `git push origin main`\n- push a branch to remote: `git psuh origin \u003cbranch-name\u003e:\u003cbranch-name\u003e`\n\n## Pull\nPulling changes from a remote repository\n\n- basic command: `git pull`\n\n## Fetch\nFetching changes from a remote repository without merging\n\n- basic command: `git fetch`\n\n# Other Useful Commands\n\n## Reset\nResetting the current branch to a specific commit\n```bash\n# basic\ngit reset HEAD\n# soft mode: \ngit reset --soft \u003ccommit-id\u003e\n# hard mode\ngit reset --hard \u003ccommit-id\u003e\n```\n\n## Revert\nReversing a commit\n\nwe should only use git revert if we want to apply the inverse of a particular commit. It doesn’t revert to the previous state of a project by removing all subsequent commits, \nit simply undoes a single commit. git revert doesn’t move ref pointers to the commit that we’re reverting, which is in contrast to other ‘undo’ commands, such as git checkout \nand git reset. Instead, these commands move the HEAD ref pointer to the specified commit.\n    \n`git revert \u003ccommit-id\u003e`\n\n## Stash\nTemporarily saving changes\n\nThe git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy\n    - if you create new file and this file have not been staged in git, then when use stash command, this file is ignored by git\n\n- basic command: `git stash`\n- if you want reapply stage and remove from stash: `git stash pop`\n- if you want reapply stage and copy from stash: `git stash apply`\n- stash options: \n    - `git stash -u` : for untrack files\n    - `git stash -a` : for all data, even ignore files\n    - `git stash list` : list of WIP (work in progress) in stash\n    - `git stash pop/apply stash@{number}` : select specific stash\n    - `git stash save \"message\"` : define description for \n    - `git stash show` : show diff\n    - `stash show -p` : view full diff between files\n- Creating a branch from your stash\n    - If the changes on your branch diverge from the changes in your stash, you may run into conflicts when popping or applying your stash. Instead, you can use git stash branch to create a new branch to apply your stashed changes to:\n        - `git stash branch add-stylesheet stash@{number}`\n\n## Tag\nCreating tags for specific commits\n\n- add : `git tag \u003ctag-name\u003e`\nflexibleTag : `git tag -a \u003ctag-name\u003e -m \"message\" \u003ccommit-id\u003e`\n- show detail : `git show \u003ctag-name\u003e`\n- list : `git tag --list`\n- best-practice : `git tag -a \u003ctag-name\u003e -m \"tag message\"`\n- show comment : `git tag -n`\n- editTag : `git tag -f \u003ctag-name\u003e \u003ccommit-id\u003e`\n- push all new tags: `git push --tags`\n\n## Bisect\n    The Git Bisect command performs a binary search to detect the commit that introduced a bug or regression in the project’s history\n    1. start the bisect -\u003e git bisect start\n    2. define bad commit -\u003e git bisect bad (current branch)\n    3. define good commit -\u003e git bisect good \u003ccommit_hash\u003e\n    4. then bisect starts to move between commits in the range of bad and good commits to find the commit which is a bug introduced there.\n    5. after finding the bug, stop the bisect -\u003e git bisect reset\n    6. then you can check that commit and revert or fix it with a new commit.\n    7. [Tutorial for Bisect] (https://www.youtube.com/watch?v=D7JJnLFOn4A\u0026t=367s)\n\n## Global Config\n```bash\ngit config --global user.name \"pouya pouryaie\"\ngit config --global user.email \"pouyapouryaie@gmail.com\"\n\n# change default branch name while creating new git repository\ngit config --global init.defaultBranch main\n```\n    \n# Reset Index\n`reset index : git rm -r --cached .`\n\n\n# Some Common Process\n\n## back file to latest station\n\n1. add file to stage\n2. git reset HEAD\n3. git checkout -- file name\n\n## alias\n\nadd command for use with alias name \u003cbr\u003e\nex: `git config --global alias.fulllog \"log --oneline --graph --decorate --all\"` \u003cbr\u003e\nthen in use: `git fulllog`\n\n## github\nHow to push or pull on a repository at github\n1. first you need create ssh-key : ssh-keygen\n2. copy content in id_rsa-public in github account ssh-key\n\n### push scenario oh Github\n\n1. if you are not repo in local:\n    * echo \"# gitdemo\" \u003e\u003e README.md\n    * git init\n    * git add README.md\n    * git commit -m \"first commit\"\n    * git remote add origin git@github.com:PouyaPouryaie/gitdemo.git\n    * git push -u origin master\n\n2. if you are have repo in local\n    * git remote add origin git@github.com:PouyaPouryaie/gitdemo.git\n    * if your repo is another server : $ git remote add origin ssh://[serverUser]@[serverIp]:/home/pouya/myrepo\n    * git push -u origin master\n\n3. if you created branch in local and you want push that as new branch in remote repo\n    * git push -u origin branchName\n\n4. if you are push from local in repo anytime\n    * git push origin master\n\n5. if you want use simple push command \n    * git config --global push.default simple\n    * git push\n\n6. if you want send tag to remote repo\n    * git push origin tagName\n    * git push --tags (send all tags)\n\n7. if you want Edit tag in remote repo\n    * git push --force origin tagName\n8. if you want Remove tag from remote repo\n    * git push --delete origin tagname\n\n# fetch \u0026 pull\n\n- for pull specific branch from remote to local \u003cbr\u003e\n`git pull origin \u003cbranch-name\u003e (recommend before pull in local create branch with same name in remote)`\n    \n- if you have 'Git refusing to merge unrelated histories' error you must be add `--allow-unrelated-histories` to pull request\n\n- pull and rebase on your branch\n`git pull --rebase`\n\n## rename remote repo in local\n```bash\ngit remote set-url origin newAddress(newName)\n```\n    \n## track remote branch on local branch\n```bash\ngit branch --set-upstream-to=origin/\u003cremote-branch\u003e \u003clocal-branch\u003e\n```\n\n## How to create a branch in remote and use it\n\n1. first create a branch in remote repository\n2. fetch in local repo and see the list of branch in remote repository: `git fetch`\n3. checkout the branch on your local: `git checkout \u003cbranch-name\u003e`\n4. work on the branch and then commit in local: `git commit -am \"\" (this commit done on the branch-name)`\n5. push branch on the remote repository: `git push`\n6. push branch on the new branch in remote: `git push \u003cremote\u003e \u003clocal-branch-name\u003e:\u003cremote-branch-name\u003e`\n\n## some remove scenario\n\n- branch:\n    - from local: `git branch -d \u003cbranchName\u003e`\n    - from remote: `git push origin -d \u003cbranchName\u003e`\n- tag:\n    - from local: `git tag -d \u003ctagname\u003e`\n    - from remote: `git push --delete origin \u003ctagName\u003e`\n\n\n## change origin and push all-things in new origin\n\n1. Setup new origin url for local repo\n```bash\ngit remote set-url origin \u003cnew-url\u003e\n```\n2. push all your branch and tags into new repo with one of below command:\n```bash\ngit push origin '*:*'\ngit push origin --all\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouyapouryaie%2Fgitdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpouyapouryaie%2Fgitdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouyapouryaie%2Fgitdemo/lists"}