{"id":18807034,"url":"https://github.com/zriyansh/git","last_synced_at":"2026-01-27T04:04:42.887Z","repository":{"id":122977100,"uuid":"453031064","full_name":"zriyansh/git","owner":"zriyansh","description":"commonly used git commands","archived":false,"fork":false,"pushed_at":"2022-02-01T15:41:10.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-22T01:11:13.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://zriyansh.github.io/git/","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/zriyansh.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-28T10:47:14.000Z","updated_at":"2022-01-28T13:13:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"698d220f-9fb6-4598-844b-2d55bcb12a8d","html_url":"https://github.com/zriyansh/git","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zriyansh/git","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zriyansh%2Fgit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zriyansh%2Fgit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zriyansh%2Fgit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zriyansh%2Fgit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zriyansh","download_url":"https://codeload.github.com/zriyansh/git/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zriyansh%2Fgit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28800960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T03:44:14.111Z","status":"ssl_error","status_checked_at":"2026-01-27T03:43:33.507Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-07T22:50:37.158Z","updated_at":"2026-01-27T04:04:42.872Z","avatar_url":"https://github.com/zriyansh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# GIT BASH COMMANDS\n## Git is a Distributed graph theory tree model.\n\nTo save your password with github permanently, make a file ```.netrc``` in ```home/\u003cusername\u003e```, add the following and then save. \n\n```\nmachine github.com\nlogin \u003clogin_github\u003e\npassword \u003cpassword_github\u003e\n```\n\nor better use SSH key method, it's difficult to get it set for the first time but that's worth it. \n\n\u003chr\u003e\n\n1. To open a file (eg .js or .html file in Windows)\n ```\n notepad fileName.fileExtension\n ``` \n\n2. CLONE\n```\ngit clone \u003curl\u003e \u003cfolder where to clone it\u003e\n```\n\n```\ngit clone --shallow\n-\u003e  if the repository is very big, this command avoids to download commits made earlier in that project.\n```\n\n\n\n3. CONFIGURATION\nto setup name and email,\n```\ngit config\n-\u003e to show all things which can be done using this command\n-\u003e configure .gitconfig file to make it behave your way, search internet\n\ngit config --global user.name \"Priyansh Khodiyar\"\n\ngit config --global user.email \"khodiyarprouansh@gmail.com\"\n\ngit config --gloabl --list\n-\u003e shows our name and email.\n-\u003e now, a text file is created that contain these details\n\ncat ~/.gitconfig\n-\u003e here it will show the name and email\n```\n\n\n\n4. BASIC COMMANDS\n```\nls -a \n-\u003e shows all the hidden folders\n\ngit init \n-\u003e cd into the project folder and type this\n\ngit init git-demo\n-\u003e git initialized only in git-demo folder\n\nclear\n-\u003e to clear the console/terminal.\n```\n\n\n5. ADD AND COMMIT AT THE SAME TIME\n```\ngit add \u003cfileName.fileExtension\u003e\n-\u003e to add single files to git\n\ngit add .\n-\u003e to add every file and folder to git\n\ngit commit -m \"type your git msg\"\n-\u003e every git commit must have a message to provide a little detail of what was changed, emojis can also be used\n\ngit commit -am \"type your commit message here\"\n-\u003e a for ADD and m for MSG\n-\u003e add and commmit in one single step can be done for MODIFIED files only, not for the newly created files.\n\ngit status\n-\u003e to check which all files that you added or commited are ready to be pushed to github or other project hosting sites.\n\n-\u003e suppose you made 2 changes to a file and you want to add only one of them\ngit add -p \u003cfilename\u003e\n-\u003e this will show [ y/n ] to add/ not add the changes made for every single changes\n\ngit diff --catched\n-\u003e shows which changes are staged for commit\n\ngit checkout \u003cfilename \u003e\n-\u003e to throw out the unwanted changes which should not be added in a file.  \n\ngit reset \u003cfilename\u003e\n-\u003e to remove the file from staging area\n```\n\n\n6. REVERT BACK \nafter we modified a file and added it to commit stage, if we want to revert back, \n```\ngit reset HEAD \u003cfileName\u003e.\n-\u003e now it's again in the modified stage, if we further want to revert those changes that we did in a file, do \n\ngit checkout -- \u003cfileName.ext\u003e \n-\u003e this is make the file like how it was before modifying it.\n```\n\n7. LOGS \n```\ngit log\n-\u003e all commits shown here, but this much info may be too much, so type \n\ngit help log \n-\u003e to get options to log \n\ngit log --oneline --graph --decorate --color --oneline\n-\u003e gives a compact and beautiful view of logs.\n```\n\n8. REMOVING FILES\n```\ngit rm \u003cfileName\u003e\n-\u003e to remove a file, but still removal needs to be commited, so do a final commit to remove files. \n```\nANOTHER WAY (OS Level) : \n```\nrm \u003cfileName.ext\u003e\n-\u003e removes file without gits info and it's there in the commit zone, but can't be commited as it can't be added back.\n\ngit add -u \n-\u003e to stage it for commit and then commit.\n```\n\n\n9. MOVING FILES (between folders)\n```\ngit mv \u003cfileName.ext\u003e \u003cfolderName\u003e\n-\u003e moving from a file in master to a folder in master. Commit these at last\n```\n\n\n10. IGNORING FILES\nlike we dont want to push .log files so ignore them, make a .gitignore file using \n```\nnotepad .gitignore\n\n*.log\n-\u003e and inside this file type this, this prevents any .log extension files to get added or commited.\n```\n\n11. SSH key Authentication \n```\ncd ~ \n-\u003e to get back to home/ root directory now type \n\ncd .ssh \n-\u003e to see if the .ssh key exist or not, if not then\n\nmkdir .ssh \ncd .ssh/\nssh-keygen -t rsa -C \"\u003cyourRegisteredEmail\u003e\"\n\n-\u003e then it will generate id_rsa and id_rsa.pub, we'll use .pub file with github.\n-\u003e SSH keys are tied to the computer. Copy the contents of .pub file and paste it in github settings at SSH settings.\n\nAfter successful authentication, type\nssh -T git@github.com\n-\u003e to get a success msg.\n-\u003e return to home directory cd ~\n```\n\n\n12. COLLABORATE WITH OTHERS (PULL REQUESTS)\ncreate a new repository in github, set everything as default. \n\nNOTE : remote means making a channel for other people to have connections with our files. \nIt can be connected to other folders of our system as well, \ne.g.\n```\ngit remote add origin ../\u003cfolder name where the remote will be setup for this repository\u003e\n```\n\nNOTE: you must be inside the git initiated folder to perform the following code below.\n\n```\ngit remote add origin git@github.com \u003cusername\u003e/\u003crepoName.git\u003e\nOR\ngit remote add origin \u003cRepository URL\u003e\n-\u003e to add the URL of your github repository so that you can push and pull changes\n\ngit remote -v\n-\u003e to check which remote URL was added\n\nthen \n\ngit push -u origin main\n-\u003e -u is done for the first time use to make a \"uplink\"\n-\u003e now our local folder repo is pushed to github\n```\nNOTE: Always first pull the changes from Github repository before making a push. \n\nNow locally we can modify the files, add and commit and then if we check the status then it will show which branch is ahead by commits as we re in sync with github(using SSH)  \n\n\n```\ngit remote remove origin \n-\u003e to remove set remotes\n``` \n\nNOTE :  While creating a new repo we add/create any file in the repository (like a readme.md file) then it will cause problem and we'll have to perform some extra commands to push your changes to Github. We'll need to first pull from our repository then push.\n\n\nand in order to make sure none has contributed/made changes to my remote repo on github, first do\n```\ngit pull origin main\nOR simply\ngit pull \n-\u003e if there is only 1 branch\n-\u003e to make sure its the same as before (best practices) and then push the changes that you did to the files of the project, to github by \n\ngit push origin master\n```\n\nANOTHER WAY :\nintead of writing \n```\ngit push origin master\n```\nto push from out local machine to github everytime. \n\ndo\n\n```\ngit branch --set-upstream-to=origin/main\n\ngit branch -vv\n-\u003e to see which all branches i have access to\n\nnow \ngit push \n-\u003e will push the changes you made, to github\n\ngit fetch \u003cRepo URL\u003e\n-\u003e to make your local repo uptodate. \n\ngit fetch upstream\n-\u003e if you already have set the upstream\n\ngit merge upstream/master\n-\u003e to get you local repo uptodate with their repo. \n```\n\n\n13. Connecting your project folder with already created emptry Github repository\n```\necho \"# New_Repository\" \u003e\u003e README.md\ngit init\ngit add README.md\ngit commit -m \"first commit\"\ngit remote add origin \u003cURL\u003e\ngit push -u origin master\n\nNote: Here URL means your Github repository link where your project will be uploaded/pushed to\n```\n\n14.  UPDATES AND GIT DIRECTORY PATH \n```\nwhich git \n-\u003e to get the path of git used\n```\n\n\n15. HOW TO GO TO THE CONTENTS OF A FILE FROM ONLY THE HASH CODE\nwhich was provided after commit.(7 digit shorterened code)\ntake that 7 digit hash code and\n```\ngit cat-file -p 7G7DF61\n```\nand then take the long code that generated and again copy that and do\n```\ngit cat-file -p XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n```\nagain a long hash will be created again repeate till you get the code inside the commited file. \n\n\n\n16. TIME TRAVEL IN GIT\n```\ngit checkout XXXXXXXX \n-\u003e it will take you to that state of commit\n-\u003e XXXXXXXX is the commit hashcode, kind of an ID of that commit\n\ngit checkout master\n-\u003e to go back again to latest position of working, if you went back in time to see initial state of your git project\n\ngit checkout \u003cfilename.ext\u003e\n-\u003e to discard the changes made recently which are not added and revert the state to HEAD position\n```\n\n\n17. SHOW CHANGES\n```\ngit diff index.txt\n-\u003e shows the changes occured in file\n\ngit diff \u003chash code(8 digit)\u003e \u003cfilename.ext\u003e\n-\u003e to show the additions occured right from that commit\n\n\ngit diff \u003chash code(8 digit)\u003e HEAD \u003cfilename.ext\u003e\n-\u003e to show the additions occured right from that commit to the position where head is present (not master)\n```\n\n18. BRANCHES (or references)\n\nNOTE: Master is equal to Main, after Github changed it's notation due to BLM. (To remove Master-Slave references)\n```\ngit branch \n-\u003e to show  the number of branches currently\n\ngit branch --v\n-\u003e to also show some extra info.\n\ngit branch cat\n-\u003e makes a new branch 'cat'\n\ngit checkout cat\n-\u003e switched  to branch cat\n-\u003e now HEAD points to cat and main points to whearever it was pointing earlier,\n-\u003e now if we commit something then master will be behind our 'cat' branch and HEAD will be the 'cat'.\n\ngit branch -d \u003cbranch name\u003e\n-\u003eremoves a branch \n```\n\n\n19. MORE BRANCHES\n\nnow that we have a 'cat' branch, let's create a dog branch\n```\ngit branch dog; git checkout dog    \n-\u003e commands to go to dog from main branch  \n-\u003e ';' is shortcut that runs 2 commands at a time\n\ngit checkout -b dog\n-\u003e now HEAD -\u003e  dog, main  Also HEAD is no longer at 'cat'. \n\n               \t\t\t\t\t cat.\nBY doing this we have 2 branches from --\u003e  main / \n\t\t\t\t               \\ \n\t\t\t\t                 dog.\n\nEXAMPLE :-initially: only index file with \"hello word\" text\ncat branch :- append \"added cat functionality\" to text file\ndog branch :- append \"added dog functionality\" to text file\n\n-\u003e now checkout master\ngit checkout master\n```\n\nNow we want to merge one by one or both at a time with the main branch.\n\n```\ngit merge  cat\n-\u003e what this does is it makes HEAD to move to 'cat' along with main to incorporate 'cat' functionality text. \n-\u003e and now HEAD -\u003e  cat, main.\n\ngit merge dog\n-\u003e now there may be merge conflicts, so we have to manually resolve this. \n\ngit mergetool \n-\u003e this tool helps to resolve issues but you need to config that first in your git project\n\ngit merge --abort\n-\u003e to abort making changes\n```\n\nSuppose merge conflict occurs then open the index file,\n```\n\u003e\u003e\u003e\u003e\u003e means here you were\n\n===== means this is what you are trying to add. \n\nnow resolve the issue, save the file (delete these \u003e\u003e\u003e\u003e\u003e and ===== symbols before saving the file)\n\n\ngit merge --continue\n-\u003e add the file and give a commit message\n```\nnow cat dog branch are merged with main and HEAD-\u003e  main\n\n\n20. BLAME\n```\ngit blame \u003cfilename\u003e\n-\u003e to checkout who made changes to particular lines and the commit associated with it\n-\u003e To the right, the contents of the file will be present\n-\u003e To the left, the name and date of commits and commit id XXXXXXX\n\ngit show XXXXXXXX\n-\u003e to see what all was changed and what was replaced. \n\ngit stash\n-\u003e reverts back me to the time when the last commit was made and ignore all the changes that I recently made, commited changes are not deleted. \n\ngit stash pop\n-\u003e to view them\n\nand then \ngit diff \u003cfilename\u003e\n-\u003e shows the changes that were made\n\ngit bisect\n-\u003e now you're long into the project and now some unit test is no longere passing which used to pass a few weeks back, this command will check going back one - one commit to see where in point of time was this test case passing, it does a binary search into your history\n-\u003e We can even give it a string of test case to look for when this case was passed in the code in which point of time. Advanced stuff. \n```\n\n\n\nBooks\n1. proGit. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzriyansh%2Fgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzriyansh%2Fgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzriyansh%2Fgit/lists"}