{"id":21231559,"url":"https://github.com/piyalidas10/git-tutorials","last_synced_at":"2025-09-07T01:33:04.820Z","repository":{"id":246686140,"uuid":"821711030","full_name":"piyalidas10/Git-Tutorials","owner":"piyalidas10","description":"Git commands","archived":false,"fork":false,"pushed_at":"2025-02-05T12:54:18.000Z","size":7255,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T02:32:30.550Z","etag":null,"topics":["git","interview","interview-questions"],"latest_commit_sha":null,"homepage":"","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/piyalidas10.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-29T08:07:00.000Z","updated_at":"2025-02-05T12:54:22.000Z","dependencies_parsed_at":"2025-09-07T01:32:10.793Z","dependency_job_id":null,"html_url":"https://github.com/piyalidas10/Git-Tutorials","commit_stats":null,"previous_names":["piyalidas10/git-tutorials"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/piyalidas10/Git-Tutorials","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FGit-Tutorials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FGit-Tutorials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FGit-Tutorials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FGit-Tutorials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piyalidas10","download_url":"https://codeload.github.com/piyalidas10/Git-Tutorials/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FGit-Tutorials/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273986612,"owners_count":25202704,"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-09-06T02:00:13.247Z","response_time":2576,"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","interview","interview-questions"],"created_at":"2024-11-20T23:47:18.051Z","updated_at":"2025-09-07T01:33:04.796Z","avatar_url":"https://github.com/piyalidas10.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Essential Commands\nGit is a version control system. Git helps you keep track of code changes.\n\nA — Files added to stage\nM — Modified files\nD — Deleted files\n\n### 1. Update local current feature branch with Develop/Master branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git stash  ---------- save you local changes / untracked files\n$ git pull origin develop -------- if want to pull from develop branch\n$ git stash apply -------- apply you local changes on develop branch's changes\n\nresolve merge conflict if you have\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 2. Push local repository content to a remote repository\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git status\n$ git add . ---------------------------------------- move your local working directory changes to staging are\n$ git commit -m \"commit msg\"  ---------------------- commit your all changes\n\ncommit few particular files\n============================================================\ngit commit file1 file2 file5 -m \"commit message\"\n\nNote: git reset  -------- opposit of \"git add .\". revet your staging changes to local working directory\n\nif remote repository already exists in git\n===========================================================\n$ git push \nif remote repository not exists in git\n===========================================================\n$ git push --set-upstream origin \u003cyour branch name\u003e\nOR\n$ git push -u origin \u003cyour branch name\u003e\n```\n\nLet me explain you using VS code. In VS code, we have changes \u0026 stage changes section in left panel. Will be easy to relate with VS Code.\n```\ngit add .   ------------ Move all local changed files to stage changes\ngit add scm-provider-category.png --------- only move particular file to stage changes\n```\n![stage changes]([http://url/to/img.png](https://miro.medium.com/v2/resize:fit:1400/format:webp/1*og7TRCo3IOQ1iWUCwPNU1w.png))\n\nif you want to un-stage the file (scm-provide-category.png)\n```\ngit reset ------------- unstage all stage changes file \u0026 move back to changes section\ngit reset scm-provider-category.png -------- unstage only a particular file\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 3. Checkout command uses\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \nLet’s say, you already pushed a file contact.html with your codes. now someone mistakenly change/delete your contact.html file. Then using git status you can see your modified files details like the following way.\n\n![checkout](https://miro.medium.com/v2/resize:fit:828/format:webp/1*VdyI7NXLOsH_DmrykakGxw.png)\n\nNow how you will get your already pushed contact.html file? Here checkout command comes to help. The checkout command retrieve the already pushed contact.html file with changes.\n\n```\ngit checkout commands match your working directory with the last commit\n\nmatch contact.html file of working directory with your last commited contact.html file\n======================================================================\n$ git checkout contact.html \n\nmatch all files of working directory with your last commit\n======================================================================\n$git checkout -f\n```\n![checkout final](https://miro.medium.com/v2/resize:fit:1100/format:webp/1*OReZbMr3lPuyzTZAxzFhhQ.png)\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 4. Git Diff\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \ngit diff compares working tree with staging area.\n\ngit diff command allows us to track the changes that are staged but not committed\n\nLet’s say, i have changed a file file.txt of my working directory. I want to compare my latest changed file.txt with my staging file.txt file. staging file not committed file.\n```\nCompare all current working directory changes with Staging area or previous commited changes one by one\n=====================================================================\n$ git diff\n\n\nCompare one particular file of current working directory with Staging area or previous commited change\n========================================================================\n$ git diff contact.html\n```\nred color highlights replaced text, green color newly added text\n\n![color highlight](https://miro.medium.com/v2/resize:fit:828/format:webp/0*RuRXz1jahSk7YKPN.png)\n\nif you run command “git add file.txt”, now again run command “git diff”. It will not show anything. Because “git add file.txt” already pushed my changed file to stage.\nIf i want to compare staging area with last commit : `git diff — staged`\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 5. Git configure for first time in your local\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git config --global user.name \"Firstname Lastname\"\n$ git config --global user.email \"myemail@example.com\"\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 6. Want to display global name \u0026 email already stored in you local Git\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git config --global user.name \"Firstname Lastname\"\n$ git config --global user.email \"myemail@example.com\"\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 7. Git Initialize\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git init --------- initialize empty git repo\n$ ls -lart --------- show all hidden folders of the current folder. you can see .git folder\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 8. Clone a repository\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \ncreate a folder -\u003e go inside the folder -\u003e run git bash\n```\ngit clone \u003cclone repo url\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 9. Merge local branch to master\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git checkout master\n$ git merge \u003clocal branch name\u003e\n$ git push -u origin master\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 10. Delete Local Branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit branch -D \u003cbranch-name\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 11. Delete Remote Branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git checkout master\n$ git push origin --delete \u003clocal branch name\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 12. Display all local branches. For current branch, display with * In front of the branch name \u0026 green color for black git background\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit branch\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 13. Create Branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit branch \u003cbranch name\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 14. Create \u0026 switching a New branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit checkout -b \u003cfeature-branch\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 15. Change Branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit checkout \u003cexisting branch name\u003e\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 16. Pull changes from existing current branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \nlet’s say that you are in a branch (feature-user). if you want to pull changes of that\n```\ngit pull\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 17. Pull changes from other branch in current branch\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \nlet’s say that you are in a branch (feature-user). if you want to pull changes of that\n```\ngit pull origin \u003cother branch name\u003e\n\nif getting screen like the following, then to EXIT from the screen press :q from the keyboard\n```\n[https://i.sstatic.net/aJC2R.png]\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 18. Pull all remote branches\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit pull — all\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 19. Display untacked files in you local\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit status\n```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 20. Remove File\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \ngit rm command deletes files both from the Git repository as well as the filesystem.\n```git rm \u003cfile name\u003e```\n\ngit rm — cached removes the file only from the Git repository, but not from the filesystem.\n```git rm — cached \u003cfile name\u003e```\n \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 21. Fetching Remote repository data\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \ngit pull copies changes from a remote repository directly into your working directory, while git fetch does not. The git fetch command only copies changes into your local Git repo.\n```\ngit fetch\n``` \n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 22. Ignoring by GIT\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \nGit will not track files and folders specified in .gitignore. When sharing your code with others, there are often files or parts of your project, you do not want to share.\n\nExamples\n\nlog files\ntemporary files\nhidden files\npersonal files\netc.\n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 23. Git logger details (how many commits with files info like author’s email, date)\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\ngit log  --------- all previous commits details\ngit log -p -5 --------- will display only last 5 commits\n\npress Q to quit to excapse from displaying git log details\n```\n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n\n### 24. Display list of all Git configurations\n\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eAnswer\u003c/b\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n#### \n```\n$ git config - global - list\nuser.name=Firstname Lastname\nuser.pasword=Admin@12      -------------------- demo test password\nuser.email=myemail@example.com\n\ngit config --global --get user.name -------------------- shows your username.\ngit config --global --get user.email -------------------- displays your email.\ngit config --global credential.helper -------------------- verify credentials.\ngit config --global    \n```\n\u003c/p\u003e\n\u003c/details\u003e\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyalidas10%2Fgit-tutorials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiyalidas10%2Fgit-tutorials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyalidas10%2Fgit-tutorials/lists"}