{"id":19010213,"url":"https://github.com/augusto11cb/git-studies","last_synced_at":"2025-10-07T19:05:38.894Z","repository":{"id":126985008,"uuid":"135294027","full_name":"Augusto11CB/Git-Studies","owner":"Augusto11CB","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-03T12:53:58.000Z","size":7232,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T21:22:40.745Z","etag":null,"topics":["git","git-tutorial","gitcommands","github"],"latest_commit_sha":null,"homepage":null,"language":null,"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/Augusto11CB.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}},"created_at":"2018-05-29T12:39:22.000Z","updated_at":"2021-06-03T12:54:00.000Z","dependencies_parsed_at":"2023-06-19T14:18:36.357Z","dependency_job_id":null,"html_url":"https://github.com/Augusto11CB/Git-Studies","commit_stats":null,"previous_names":["augusto11cb/git-studies","augusto11c/git-studies"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Augusto11CB%2FGit-Studies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Augusto11CB%2FGit-Studies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Augusto11CB%2FGit-Studies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Augusto11CB%2FGit-Studies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Augusto11CB","download_url":"https://codeload.github.com/Augusto11CB/Git-Studies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240037635,"owners_count":19737986,"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","git-tutorial","gitcommands","github"],"created_at":"2024-11-08T19:10:25.391Z","updated_at":"2025-10-07T19:05:38.807Z","avatar_url":"https://github.com/Augusto11CB.png","language":null,"readme":"# Git-Studies\n\n## To Study\n[Git Hooks](https://www.atlassian.com/git/tutorials/git-hooks)\n[Git Cherry Pick](https://www.atlassian.com/git/tutorials/cherry-pick)\n\n## Index\nTODO\n\n## How to Delete Branch Locally and Remotely\n```\n$ git push -d \u003cremote_name\u003e \u003cbranch_name\u003e\n$ git branch -d \u003cbranch_name\u003e\n```\n\nNote that in most cases the remote name is origin. In such a case you'll have to use the command like so.\n\n```\n$ git push -d origin \u003cbranch_name\u003e\n```\n\n## Git Log Useful Commands\n\n### Cloning git repository when folder and files already exist\n\n\n```\ngit init\ngit remote add origin \u003cmy-github-rep.git\u003e\ngit fetch\ngit branch --set-upstream-to=origin/master\n```\n\n### List of remotes for a Git repository?\n```\n$ git remote\niqandreas\noctopress\norigin\n```\n\n### Showing one commit per line\n`$ git log --oneline`\n\n### The `--stat` \nFlag that can be used to display the files that have been changed in the commit, as well as the number of lines that have been added or deleted.\n`$ git log --stat`\n\n### How to see changes in a file?\nThis flag can be used to display the actual changes made to a file.\n`$ git log -p`\n\n\n## Push an existing repository from the command line\n`$ git remote add origin git@github.com:AugustoCalado/Test-Repo.git`\n\n`$ git push -u origin master`\n\n## How to change the remote a branch is tracking?\n`$ git branch branch_name -u your_new_remote/branch_name`\n\n## How to solve git refusing to merge unrelated histories on rebase?\n\n`$ git pull origin master --allow-unrelated-histories`\n\n`$ git merge origin origin/master`\n\n... add and commit here...\n\n`$ git push origin master`\n\n## The git stash \nUse git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. \n\n### The git stash -p \nThis command will then show a dialog like the following, for every hunk in your possible commit\n`Stash this hunk [y,n,q,a,d,e,?]?`\n\n#### Meaning of the letters\n```\n   y - stage this hunk\n           n - do not stage this hunk\n           q - quit; do not stage this hunk nor any of the remaining ones\n           a - stage this hunk and all later hunks in the file\n           d - do not stage this hunk nor any of the later hunks in the file\n           g - select a hunk to go to\n           / - search for a hunk matching the given regex\n           j - leave this hunk undecided, see next undecided hunk\n           J - leave this hunk undecided, see next hunk\n           k - leave this hunk undecided, see previous undecided hunk\n           K - leave this hunk undecided, see previous hunk\n           s - split the current hunk into smaller hunks\n           e - manually edit the current hunk\n           ? - print help\n```\n\nA hunk is a coherent diff of lines as git-diff produces it. To select a single file you'll have to decline adding hunks as long as you reach that file, then you might add all hunks from that file.\n\n**Observation**\nUsing the --patch-option is possible on different git commands (f.e. stash, commit and add).\n\n### Stage specific files\n`$ git stash push -m stash_name example/file/path/and/file.html`\n\n### The git stash branch \u003cbranch_name\u003e [\u003cstashnumber\u003e]\nCreates and checks out a new branch named \u003cbranchname\u003e starting from the commit at which the \u003cstash\u003e was originally created, applies the changes recorded in \u003cstash\u003e to the new working tree. It then drops the stash. \n   \n### Show files inside a stash\n`$ git stash show -p stash@{x}`\n\n#### Show only the files name inside a stash\n`$ git stash list --name-status`\n\n### How can to git stash a specific file?\n`$ git stash push -m welcome_cart app/views/cart/filename.ext`\n\n## Push Existing Repo to a New and Different Remote Repo Server?\n\n```\n$ git remote add github-repo \u003cgithub-repo-url\u003e\n$ git checkout master\n$ git push github-repo master    # push current-repo master branch changes to github-repo master branch\n\n$ git remote #shows the remotes tracked\n```\n\n## How to rename Git Local and Remote Branches\n\n1. Rename Local Branch\n\n`$ git branch -m new-name`\n\n   * If i am on a different branch\n   \n   `$ git branch -m old-name new-name`\n   \n2. Delete the old-name remote branch and PUSH the new-name local branch\n\n`$ git push origin :old-name new-name`\n\n3. Reset upstream branch for the new\n\n`$ git push origin -u ne-name`\n\n\n## Create Branch from a Previous commit\n\n`$ git branch branchname \u003csha1-of-commit\u003e`\n\nusing a symbolic reference:\n\n`$ git branch branchname HEAD~3`\n\nTo checkout the branch when creating it, use:\n\n`$ git checkout -b branchname \u003csha1-of-commit or HEAD~3\u003e`\n\n## How Can I Determine the Url That a Local Git Repository Was Originally Cloned From?\n`$ git remote get-url origin`\n\n`$ git remote -v`\n\n`$ git remote show origin`\n\n## How to change repo cloned using https to ssh?\n\n1. remove HTTP remote (for example with origin):\n```\ngit remote remove origin\n```\n\n2. add the SSH remote\n```\ngit remote add origin user@example.com:path/to/project.git\n```\n\n3. set the branch's remote again with\n```\ngit push -u origin master\n\nor\n\ngit branch --set-upstream-to=origin master\n```\n\n## How to Untrack Files Already Added to Git Repository Based on .gitignore\n1. Commit all changes\n\n2. Remove everything from the repository\n\n`$ git rm -r --cached .`\n\n   - rm is the remove command\n\n   - `-r` will allow recursive removal\n\n   - `–cached` will only remove files from the index.\n\n3. Re add everything\n\n`$ git add .`\n\n4. Commit\n\n`git commit -m \".gitignore fix\"`\n\n## How to Correct a Commit Date\nRebase to the commit immediately prior to the commit with the wrong date\n\n`$ git rebase \u003ccommit hash\u003e -i`\n\n\nResult:\n```\npick af09d0a Log and add new dependency   # Commit with wrong date\n\npick 4e37143 exchanging stop by timeout for buffersize\n\npick 21fc337 Added simple styles in home.html\n\npick 8dc79f6 create readme             \n```\n\nReplace pick with e (edit) on the line with that commit (the first one)\n```\ne af09d0a Log and add new dependency   # Commit with wrong date\n\npick 4e37143 exchanging stop by timeout for buffersize\n\npick 21fc337 Added simple styles in home.html\n\npick 8dc79f6 create readme             \n```\n\nAdjust the commit date with \n`$ git commit --amend --no-edit --date \"6 Apr 2018\"`\n\n\nto change the commit date instead of the author date:\n\n`GIT_COMMITTER_DATE=\"Wed Feb 16 14:00 2011 +0100\" git commit --amend`\n\n\n```\nGIT_COMMITTER_DATE=\"Mon 20 Aug 2018 20:19:19 BST\" git commit --amend --no-edit --date \"Mon 20 Aug 2018 20:19:19 BST\"\n```\n\n\nFinish by typing the follow command\n`$ git rebase --continue`\n\n[RFC 2822 Formater](https://timestampgenerator.com/1604371652/-03:00)\n   \n## Creating tags from the command line\nTo create a tag on your current branch, run this:\n\ngit tag \u003ctagname\u003e\n### Include a Description with a Tag\n- `$ git tag \u003ctagname\u003e -a`\n\n### Push Tags to Remote Repo\n- `$ git push origin --tags`\n\n### Push a Single Tag to Remote Repo\n- `$ git push origin \u003ctag\u003e`\n\n### To Delete Local Tag\n- `$ git tag -d \u003ctag\u003e`\n- `$ git push origin :refs/tags/\u003ctag\u003e`\n   \n## References\n[merging-vs-rebasing](https://www.atlassian.com/git/tutorials/merging-vs-rebasing)\n[Resetting, Checking Out \u0026 Reverting](https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting)\n[Advanced Git Log](https://www.atlassian.com/git/tutorials/git-log)\n[Merge Strategy](https://www.atlassian.com/git/tutorials/using-branches/merge-strategy)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugusto11cb%2Fgit-studies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faugusto11cb%2Fgit-studies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugusto11cb%2Fgit-studies/lists"}