{"id":26395742,"url":"https://github.com/srivatsa17/git-commands","last_synced_at":"2025-03-17T11:19:10.102Z","repository":{"id":51537469,"uuid":"520456758","full_name":"srivatsa17/Git-commands","owner":"srivatsa17","description":"This repo contains a list of useful git commands along with their examples","archived":false,"fork":false,"pushed_at":"2023-04-06T07:07:57.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-07-29T10:49:28.847Z","etag":null,"topics":["git"],"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/srivatsa17.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}},"created_at":"2022-08-02T10:44:50.000Z","updated_at":"2023-07-29T10:49:28.847Z","dependencies_parsed_at":"2023-02-12T03:10:20.674Z","dependency_job_id":null,"html_url":"https://github.com/srivatsa17/Git-commands","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srivatsa17%2FGit-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srivatsa17%2FGit-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srivatsa17%2FGit-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srivatsa17%2FGit-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srivatsa17","download_url":"https://codeload.github.com/srivatsa17/Git-commands/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244022681,"owners_count":20385134,"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"],"created_at":"2025-03-17T11:19:09.448Z","updated_at":"2025-03-17T11:19:10.094Z","avatar_url":"https://github.com/srivatsa17.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git commands\n## 1. Configure username and email\n**Command**\n```\n$ git config --global user.name \"\u003cusername\u003e\"\n$ git config --global user.email \u003cemail id\u003e\n```\n**Example**\n```\n$ git config --global user.name \"John Doe\"\n$ git config --global user.email johndoe@example.com\n```\n## 2. Create a new local repository\n**Command**\n```\n$ git init\n```\n\u003e Note: Create a folder in your system and run this command to create a local repository.\n\n## 3. Clone a repository\n**Command**\n```\n$ git clone \u003crepository url\u003e\n```\n**Example**\n```\n$ git clone https://github.com/srivatsa17/Git-commands.git\n```\n## 4. Create a new branch, switch to it and push to remote\n**Command**\n```\n$ git checkout -b \u003cnew branch\u003e \u003cexisting branch\u003e\n$ git push \u003cremote name\u003e \u003cnew branch\u003e\n```\n**Example**\n```\n$ git checkout -b development master\n$ git push origin development\n```\n## 5. Switch from one branch to another\n**Command**\n```\n$ git checkout \u003cexisting branch\u003e\n```\n**Example**\n```\n$ git checkout development\n```\n## 6. List current branch\n**Command**\n```\n$ git branch\n```\n## 7. List all branches\n**Command**\n```\n$ git branch -a\n```\n## 8. Push all local branches to remote\n**Command**\n```\n$ git push -all \u003cremote name\u003e\n```\n**Example**\n```\n$ git push -all origin \n```\n## 9. Delete a particular branch from remote and local\n**Command**\n```\n$ git push -d \u003cremote name\u003e \u003cbranch name\u003e\n$ git branch -d \u003cbranch name\u003e\n```\n**Example**\n```\n$ git push -d origin development\n$ git branch -d development\n```\n## 10. Adding a changed file to staging\n**Command**\n```\n$ git add \u003cfilename\u003e\n```\n**Example**\n```\n$ git add README.md\n```\n## 11. Adding multiple changed files to staging\n**Command**\n```\n$ git add *\n```\n## 12. Commit changes to head but not to remote\n**Command**\n```\n$ git commit -m \"Commit message\"\n```\n**Example**\n```\n$ git commit -m \"First commit\"\n```\n## 13. Push changes to remote\n**Command**\n```\n$ git push \u003cremote name\u003e \u003cbranch name\u003e\n```\n**Example**\n```\n$ git commit origin master\n```\n\u003e Note: If upstream branch is already configured, just run `$ git push`\n\n## 14. Get status of changed files\n**Command**\n```\n$ git status\n```\n## 15. Fetch and merge changes on the remote server to your working directory\n**Command**\n```\n$ git pull\n```\n## 16. Merge a branch into current branch\n**Command**\n```\n$ git merge \u003cbranch name\u003e\n```\n**Example**\n```\n$ git merge development\n```\n\u003e If current branch is master, this will merge branch development into master.\n\n## 17. See the difference between previous and current versions of file modified\n**Command**\n```\n$ git diff\n```\n## 18. Reset/Undo the files modified to its previous version\n**Command**\n```\n$ git reset\n```\n## 19. Stash the changes for later use\n**Command**\n```\n$ git stash\n```\n\u003e This command takes the uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.\n\n## 20. Re-applying stashed changes\n**Command**\n```\n$ git stash pop\n```\n\n## 21. Create Tags\n**Command**\n```\n$ git tag \u003ctagname\u003e\n```\n**Example**\n```\n$ git tag 2022.05\n```\n## 22. List all Tags\n**Command**\n```\n$ git tag -l\n```\n## 23. List the remote name\n**Command**\n```\n$ git remote\n```\n## 24. List all the remotes\n**Command**\n```\n$ git remote -v\n```\n## 25. List the commit logs\n**Command**\n```\n$ git log\n```\n## 26. Print the commit logs\n**Command**\n```\n$ git log -p\n```\n## 27. Reverting the commit\n**Command**\n```\n$ git revert \u003ccommit\u003e\n```\n**Example**\n```\n$ git revert d8ed902ffe7c1529d02d9a4857c1f541e2e0ce27\n```\n## 28. Replace the previous commit message\n**Command**\n```\n$ git commit --amend -m \"New commit message\"\n```\n**Example**\n```\n$ git commit --amend -m \"Updated message\"\n```\n## 29. Searching in git\n**Command**\n```\n$ git grep \u003csearchable string\u003e\n```\n**Example**\n```\n$ git grep \"foo()\"\n```\n## 30. Revert a git pull or move to a specific version of your code\n**Command**\n```\n$ git reflog\n$ git reset --hard \u003ccommit ID\u003e\n```\n\u003e `git reflog` will give the list of commit hashID's\n\u003e `git reset --hard \u003ccommit ID\u003e` will only make changes in local repo\n\u003e `git push --force` is required if changes has to be pushed to remote server\n\n**Example**\n```\n$ git reset --hard 95377807\n```\n\u003e This will move our code into previous commit with ID 95377807\n## 31. Reset the untracked files\n**Command**\n```\n$ git restore /path/to/folder\n```\n\u003e `git restore .` will reset all the files to its original state\n## 32. Copy a commit from one branch to another without merging of branches.\n**Command**\n```\n$ git checkout \u003cnew branch where you need the commit\u003e\n$ git cherry-pick \u003ccommit hash\u003e\n$ git push\n```\n**Example**\n```\n$ git checkout master\n$ git cherry-pick a885370\n$ git push\n```\n\u003e Suppose i have branch development with commit hash a885370. I switch to branch master and use cherry pick command.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrivatsa17%2Fgit-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrivatsa17%2Fgit-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrivatsa17%2Fgit-commands/lists"}