{"id":28527535,"url":"https://github.com/peanuts-83/git-howto","last_synced_at":"2025-08-09T08:28:53.571Z","repository":{"id":115484806,"uuid":"487892423","full_name":"Peanuts-83/Git-HowTo","owner":"Peanuts-83","description":"Git practice \u0026 commands","archived":false,"fork":false,"pushed_at":"2024-01-13T15:58:27.000Z","size":382,"stargazers_count":0,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T12:13:49.538Z","etag":null,"topics":["git","howto"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Peanuts-83.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-05-02T15:17:07.000Z","updated_at":"2025-05-09T06:52:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"794ea104-cc70-4532-a5f9-b6651c4cb796","html_url":"https://github.com/Peanuts-83/Git-HowTo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Peanuts-83/Git-HowTo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peanuts-83%2FGit-HowTo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peanuts-83%2FGit-HowTo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peanuts-83%2FGit-HowTo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peanuts-83%2FGit-HowTo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Peanuts-83","download_url":"https://codeload.github.com/Peanuts-83/Git-HowTo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Peanuts-83%2FGit-HowTo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262566830,"owners_count":23329680,"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":["git","howto"],"created_at":"2025-06-09T12:13:49.686Z","updated_at":"2025-06-29T09:02:31.533Z","avatar_url":"https://github.com/Peanuts-83.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HowTo use Git - for Learning purpose\nto ignore some files/folders and even don't display them on git status, if .gitignore is not enough, add unwanted files ref in this text file : **.git/info/exclude**\n\n[Git-CheatSheet.pdf](./github-git-cheat-sheet.pdf)\n\n## BEGIN\n\n### General info\n\n```bash\ngit status\ngit reflog      // see any action made by user!\ngit log         // see commits on branch\ngit branch -avv // see all branches\ngit remote -v   // see remote url // -vv for more details\n```\n\n### Create new repo\ngit should be configured to get \"main\" brach by default\n\n```bash\necho \"# Git-test\" \u003e\u003e README.md\ngit init\ngit add README.md\ngit commit -m \"first commit\"\ngit remote add origin git@github.com:Peanuts-83/Git-test.git\ngit fetch                // get all remote branches \u0026 history commits\ngit push -u origin/main  // -u = --set-upstream-to=origin/main   // origin = remote-repo-url // main = remote-branch\n```\n\n### Push an existing repo\n\n```bash\ngit remote add origin git@github.com:Peanuts-83/Git-test.git\ngit push -u origin main\n```\n\n### Import a repo (if submodules inside, only submodules ref, no submodule files imported)\n\n```bash\ngit clone git@github.com:Peanuts-83/Git-test.git\n```\n\n### Commit all \u0026 push\n\n```bash\ngit status\ngit add .\ngit commit -m 'commit message'\ngit push\n```\n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\n### Push remoteRepo choosing local:remote branch\n\n```bash\ngit push origin production:master\n```\n\n### Undelete local files (after error)\n\nDeleted files will be restored IF they have been previously validated in Git.\n\n```bash\ngit ls-files -d | xargs git checkout\n```\n\n## SUBMODULES\n\nref : https://git-scm.com/book/fr/v2/Utilitaires-Git-Sous-modules\n\n### Add a repo (submodule) to another repo\n\n```bash\ngit submodule add git@github.com:Peanuts-83/Git-test.git\ngit submodule add git@github.com:Peanuts-83/Git-test.git folderName     // optional\n```\n\n### Import a repo with submodules content files\n\n```bash\ngit clone --recurse-submodules git@github.com:Peanuts-83/Git-test.git\n```\n\n### Import submodules content files AFTER basic git clone repo (forgot --recursive-submodules option)\n\n```bash\ngit submodule update --init --recursive\n```\n\n### TRACK a specific branch on submodule repo\n\nref : https://stackoverflow.com/questions/1777854/how-can-i-specify-a-branch-tag-when-adding-a-git-submodule\n\nMake sure parent repo knows its submodule tracks a branch\n\n```bash\ngit config -f .gitmodules submodule.\u003cpath\u003e.branch \u003cbranch\u003e\ngit config -f .gitmodules submodule.front.branch production\n```\nTarget right branch in your submodule folder (here my *main* submodule branch will follow remote *production* branch)\n\n```bash\ngit branch -u origin/production\n```\n\n### Remove a submodule\n\nref : https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule/36593218#36593218\n\n```bash\ngit submodule deinit -f \u003cpathToSubmodule\u003e\nrm -rf .git/modules/\u003cpathToSubmodule\u003e\ngit rm -f \u003cpathToSubmodule\u003e\n```\n\n## FILES \u0026 DIR\n\n### COPY file or dir from another branch\n\n```bash\ngit checkout branchName fileOrDirName\n```\n\n### REMOVE file or dir only on remote\n\n```bash\ngit rm --cached fileName\ngit commit -m'fileName removed'\ngit push\n```\n\n## BRANCHES\n\n[https://learngitbranching.js.org](https://learngitbranching.js.org)\n### CREATE branch \u0026 go on it\n=======\n## BRANCHES\n\n### Create branch \u0026 go on it\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e 05312000ee67288ec57624deaf70634999b5b63c\n\n```bash\ngit branch branchName\ngit checkout branchName\n// or short command\ngit checkout -b branchName\n```\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\n\n### COPY branch or commit under HEAD\n\nOriginals remain the same\n\n```bash\ngit cherry-pick branch1 branch2 de9a6fb // branch or commit names\n```\n\n### MERGE branch\n\nMerged branch ends to merge point. Original branches remain the same.\nGet merged branch to new commit on active branch.\u0026nbsp;\n\n**CAUTION** : Deleted common files on any branch are deleted!\n\n```bash\ngit checkout main\ngit merge branch2       // branch2 comes to main in new commit ahead last commit on main\n\nmain:       A--B--C          main:    A--B--C--F \nbranch2 :     \\D--E          branch2:   \\D--E/ \n```\n\n### REBASE branch\n\nPlaces HEAD branch ahead rebased branch. Original branches are changed, history rewritten...\nDestroys active branch to put it ahead on rebased branch.\u0026nbsp;\n\n**CAUTION** : Do not use on public branch used by others!\n\n```bash\ngit checkout branch1\ngit rebase main         // branch1 comes ahead main\n\nmain:       A--B--C          main:    A--B--C--D--E\nbranch2 :     \\D--E          branch2: no more\n```\n\n### DELETE branch\n\nPlaces HEAD branch on other branch before deleting.\n\n**CAUTION** : Do not use on public branch used by others!\n\n```bash\ngit branch -d \u003cbranchName\u003e  // -D for delet --force\n```\n\n### UNDO changes, only on local repo\n```bash\ngit reset                      // clear staging area\ngit reset \u003cfile\u003e               // clear file from staging area\ngit revert \u003ccommit-hash\u003e       // creates a new commit to undo changes made by selected commit\n```\nFrom commit C:\u0026nbsp;\n\ngit reset --soft A   // will move HEAD and branch to commit A; staging and working directory will still be at state of C.\u0026nbsp;\n\ngit reset --mixed A  // will move HEAD and branch to commit A, and staging; working directory will still be at state of C.\u0026nbsp;\n\ngit reset --hard A  // will move HEAD and branch to commit A, staging and working directory; you will go back to the state of A completely.\n=======\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e 05312000ee67288ec57624deaf70634999b5b63c\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeanuts-83%2Fgit-howto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeanuts-83%2Fgit-howto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeanuts-83%2Fgit-howto/lists"}