{"id":18995971,"url":"https://github.com/vindecodex/gitguide","last_synced_at":"2025-04-22T13:48:58.861Z","repository":{"id":56281423,"uuid":"194184193","full_name":"vindecodex/gitguide","owner":"vindecodex","description":"Guide for Git","archived":false,"fork":false,"pushed_at":"2020-11-17T02:03:24.000Z","size":82,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-13T19:59:16.335Z","etag":null,"topics":["git","guide"],"latest_commit_sha":null,"homepage":"","language":null,"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/vindecodex.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}},"created_at":"2019-06-28T01:14:25.000Z","updated_at":"2022-05-23T04:47:16.000Z","dependencies_parsed_at":"2022-08-15T16:00:25.352Z","dependency_job_id":null,"html_url":"https://github.com/vindecodex/gitguide","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/vindecodex%2Fgitguide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vindecodex%2Fgitguide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vindecodex%2Fgitguide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vindecodex%2Fgitguide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vindecodex","download_url":"https://codeload.github.com/vindecodex/gitguide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250252038,"owners_count":21399926,"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","guide"],"created_at":"2024-11-08T17:33:32.621Z","updated_at":"2025-04-22T13:48:58.842Z","avatar_url":"https://github.com/vindecodex.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"***\n## ~/.gitconfig\n\n\u003e Configure username\n\n``` php\n$ git config --global user.name \"[name]\"\n```\n\n\u003e Configure email\n\n``` php\n$ git config --global user.email \"[email address]\"\n```\n\n## Remote\n\n`git remote` - to display remote associated by the repository.\n\n`git remote add \u003cname\u003e \u003curl/path\u003e` - to add a remote repository. for more [checkout](/tips.md)\n\n\u003e Listing Remote\n\n`git remote`\n\n\n\u003e Deleting a Remote\n\n`git remote rm [remotename]`\n\n***\n## Create New Repository\n1. Create Repo on Github\n2. `git init` on local directory\n3. copy repo url (use the ssh)\n4. `git remote add origin [repo url you copy on step 3]`\n5. `git add .`\n6. `git commit -m \"your message\"`\n7. `git push origin master` (if got Permission Error try [this](https://github.com/vindecodex/gitguide/blob/master/fixPermisionError.md))\n8. To add Security on commiting you can follow this [guide](https://help.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key)\n8.1. If you done assigning gpg key to your github, dont forget to tell git about your gpg by doing these:\n```php\n$ git config --global user.signingkey \u003cPASTE_LONG_KEY_HERE\u003e\n$ git config --global commit.gpgsign true\n```\n## Or Download Existing Repo\n``` php\ngit clone [urlofrepo]\n```\n***\n## Create branch and merging branch to the master\n\u003eYou can create branch to create/upgrade/edit the existing file without affecting the main/master branch\n\n```php\n$ git branch branchname\n```\n\n\u003eTo enter to our new branch\n\n```php\n$ git checkout branchname\n```\n\n\u003eYou can checkout different branch created by anyone on your project\n\n```php\n$ git add .\n$ git commit -m \"Your message here\"\n$ git push origin branchname\n```\n\n\u003eAdding new files in our branch\n\n\u003eAfter pushing to origin branchname a link will be given to the terminal, click it while pressing cmd on mac, i think ctrl for windows\n\n\u003eIt will redirect to the pull request on github page\n\n\u003eClick Create pull request\n\n```php\n$ git checkout master\n``` \n\n\u003eTo go back to the master branch\n\n```php\n$ git merge branchname\n$ git push origin master\n```\n\n\u003eTo merge our changes on our branch to the master\n\n\u003eAnd push to our master to fully added to the main project\n\n***\n\n## Check for changes\n\n```php\n$ git status\n```\n\n\u003echeck if there is added, deleted or modified files so that you can start running the `git add` and `git commit`\n\n```php\n$ git diff\n```\n\n\u003eto see changes of files that are not yet added by `git add .` to the master branch\n\n```php\n$ git diff branchA branchB\n```\n\n\u003eto see changes between two branches\n\n```php\n$ git diff --staged\n```\n\n\u003eto see changes of files that are already added by `git add .` to the master\n\n\u003eafter you `git add .` those files are in staging or ready to be commited\n\n```php\n$ git reset filename\n```\n\n\u003eto unstage the files but the contents of your current work will not be affected, it will just remove the added files for staging\n\n```php\n$ git log\n```\n\n\u003edisplay all commited versions\n\n```php\n$ git log -1\n```\n\n\u003edisplay only the last commit\n\n## Rebase\n\n\u003eif you commited two times and the last commit just had a few changes and doesnt deserve to be commited then we can delete it without affecting the contents, only the commit will be removed but not its content or it will merge the last commit to the first commit\n\n```php\n$ git rebase -i HEAD~n //n here represents a number of how many commits will be modified\n```\n\n\u003eif you want the commit will not be added but only its content we use this\n\n\u003eexample we just commited for one time and push it to repo and then we update just a few code because got a wrong spelling then commit again, then its not really deserve to be commited.\n\n```php\n$ git rebase -i HEAD~2\n```\n\n![img1](img/img1.png)\n\n```\nyellow is the action\nlight blue is the commit code\npink is the commit message\n```\n\n\u003ewe want to merge committed A content to the add edit commit because A has just a few changes and it doesnt need to be commited\n\n![img1](img/img2.png)\n\n\u003e**pick** is for the commited\n\n\u003e**f** is for **fixup**\n\n\u003ewhen using fixup you need HEAD\\~2 or greater than 2 because you need one commit to merge the other one, you cannot use fixup if only HEAD\\~1\n\n\u003eto edit the files is press **i**, and press **esc** to leave edit mode and press **:(shift ;)** then press **wq** for write quite\n\n```php\n$ git push origin master -f\n```\n\n\u003eto push our changes to repo we need to add -f because we used rebase, remember always when using rebase you need to add -f when pushing\n\n![img1](img/img3.png)\n\n\u003e**d** for **drop**\n\u003ethis will delete the commited and also the contents entirely\n\n```php\n$ git push origin master -f\n```\n\n\u003eif your branch is out of date or not the latest version from the origin master and to avoid build errors, ci errors, conflicts\n\n```php\n$ git fetch origin //fetch latest origin\n$ git rebase origin/master\n```\n\n\u003enow you are now top of the latest version!\n\n***\n# Git Add\n\n\u003ecommit specific file\n\n```php\n$ git add [filename]\n```\n\n\u003ecommit all in a directory\n\n```php\n$ git add .\n```\n\n\u003ecommit everything included sub directories\n\n```php\n$ git add . -A\n```\n\n***\n\n# Commit\n\n\u003eadd to staging\n\n```php\n$ git commit -m \"you message\"\n```\n\n\u003eadd another file from previous commit/staging\n\n```php\n$ git add [file you want to add from previous commit]\n$ git commit --amend\n```\n\n\u003eit will prompt for a new commit message\n\n\u003eUncommit Committed Files\n\n```php\n$ git reset HEAD~\n```\n\n# Show Sorted Branch\n\n\u003eGet a list of branches ordered by most recent commit\n\u003euse the `--sort=-committerdate` option of [git for-each-ref](https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-for-each-ref.html)\n\n```php\n$ git for-each-ref --sort=-committerdate refs/heads/\n```\n\n\u003eor using git branch (since version 2.7.0)\n\n```php\ngit branch --sort=-committerdate  # DESC\ngit branch --sort=committerdate  # ASC\n```\n\n***\n\n# Fetching (Don't Care Local Changes)\n\n\u003e Be sure to stash all your local changes because it will be deleted when doing these.\n\u003e This will be a fresh files from repo (to avoid cloning again and again)\n\n```php\n$git fetch --all\n$git reset --hard origin/master\n```\n\n***\n\n# Other way on cleaning local and fetching latest repo\n\n\u003e To remove the committed files on your local\n\n```php\n$ git reset --hard HEAD^\n```\n\n\u003e To remove the uncommitted files on your local\n\n```php\n$ git clean -fd\n```\n\n\u003e You can choose one of the command above or do it both according to your needs.\n\u003e After running above commands run below command\n\n```php\n$ git pull\n```\n\n***\n\n# Stash\n\n\u003egit stash is to set aside what you are editing then go back to it later\n\u003eif you had edit something then want to reset but you want it to be save you need to use **stash**\n\n```php\n$ git stash\n```\n\n\u003enow you stash you local modification\n\n\u003eand now you edit alot but want to go back from what you stash lately.\n\n```php\n$ git stash pop\n```\n\n\u003ethis will pop the latest stashed\n\n\u003eif you stashed alot you can use \n\n```php\n$ git stash list\n```\n\n\u003eto drop or delete a stash you can use\n\n```php\n$ git stash drop\n```\n\n\u003ethis will delete latest stashed\n\n\u003eto get the specific stash\n\n```php\n$ git stash pop stash@{n}\n```\n\n***\n\n# Updating Forked repo\n\n```php\n// create a new remote from original repo\n$ git remote add upstream [ssh or https url of the repo]\n```\n\n```php\n// fetch from that original repo\n$ git fetch upstream\n```\n\n```php\n// rebase from that original repo branch [master or main]\n$ git rebase upstream/master\n```\n\n```php\n// push your updated local branch to your forked repository\n$ git push origin master --force\n```\n\n***\n\n# Creating Alias\n\n[Creating Aliases](https://github.com/vindecodex/bashrc)\n\n# Passing Commits to another branch\n\n```php\n// on your branch that holds the commit you want to pass\n$ git log\n// copy the commit hash found\n$ git checkout [branch that will copy the commit]\n$ git reset --hard [hash of the commit you want to copy from the other branch]\n// remove the [brackets]\n```\n\n# Renaming Branch from local and remote repository.\n\n```php\n// head must be on your old branch when doing this.\n$ git branch -m [new branch name]\n// renaming local branch\n$ git push origin -u [new branch name]\n// delete remote branch\n$ git push origin --delete [old branch name]\n```\n\n# Multiple Git Users with SSH\n\n[Follow this Guide](/multiple-git-users-with-ssh.md)\n\n### Guide on Contributing\n1. Fork this repo.\n\n2. Create a branch\n\n3. Push you changes \n\n4. Create a PR\n\n# Other useful tips\n\n[TIPS](/tips.md)\n\n***\n\u003eIf you see something that needs improvement please help by creating a pull request. I also suggest play git **[here](https://learngitbranching.js.org/)**\n***\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvindecodex%2Fgitguide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvindecodex%2Fgitguide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvindecodex%2Fgitguide/lists"}