{"id":20003664,"url":"https://github.com/xenioushk/useful-git-commands","last_synced_at":"2025-06-10T17:09:57.123Z","repository":{"id":146627068,"uuid":"426826897","full_name":"xenioushk/useful-git-commands","owner":"xenioushk","description":"This documentation provides a quick setup process of Git and a few useful commands.","archived":false,"fork":false,"pushed_at":"2025-04-12T18:58:10.000Z","size":191,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T19:39:40.373Z","etag":null,"topics":["git-commands","git-tutorials","github","github-config"],"latest_commit_sha":null,"homepage":"https://bluewindlab.net/useful-git-commands-that-you-should-know/","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/xenioushk.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}},"created_at":"2021-11-11T00:59:33.000Z","updated_at":"2025-04-12T18:58:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd3e9b96-128a-4c81-9293-61105a0dcf1e","html_url":"https://github.com/xenioushk/useful-git-commands","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/xenioushk%2Fuseful-git-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenioushk%2Fuseful-git-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenioushk%2Fuseful-git-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenioushk%2Fuseful-git-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xenioushk","download_url":"https://codeload.github.com/xenioushk/useful-git-commands/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenioushk%2Fuseful-git-commands/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259114576,"owners_count":22807252,"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-commands","git-tutorials","github","github-config"],"created_at":"2024-11-13T05:26:38.021Z","updated_at":"2025-06-10T17:09:57.109Z","avatar_url":"https://github.com/xenioushk.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Useful \u0026 Frequently Used git Commands\n\nThis documentation provides a quick setup process of Git and a few useful commands.\n\n## ✅ Git application setup\n\n- Download git application from https://git-scm.com\n- Install it on your computer.\n- Open the terminal (Mac) or Poweshell (Windows).\n- Once done, run the following command to check the git version.\n\n```bash\ngit --version\n```\n\nor\n\n```bash\ngit -v\n```\n\n**👉 Output**\n\n![git version check output](/previews/git_version_check_output.jpg)\n\n## ✅ Setup git user name and email\n\nThe following commands allow you to set username and email address globally. 🤗\n\n```bash\ngit config --global user.name \"Your Name\"\ngit config --global user.email \"Your Email\"\n```\n\nYou can also set specific username and email address for your current project. 💪\n\n```bash\ngit config user.name \"Your Name\"\ngit config user.email \"Your Email\"\n```\n\n### 👉 Validate/Check user information\n\n```bash\ngit config --global user.name\ngit config --global user.email\n```\n\n### 👉 Initalize a git repository\n\nThe following command allows you to initialize a fresh local git repository to your project.\n\n```bash\ngit init\n```\n\n### 👉 Check git status\n\nThe following command will display the current status of the added/updated/deleted files.\n\n```bash\ngit status\n```\n\n### 👉 git push \u0026 pull commands\n\n```bash\n\ngit add -A\n\ngit commit -m \"your_custom_commit_message_in_here\"\n\ngit commit -am \"your custom_commit_message_in_here\"\n\ngit remote add origin \"git_remote_repository_url\"\n\n//set upstream. (rename the remote from origin to upstream)\n\ngit remote rename origin upstream\n\n// Using -u, you can set the upstream branch for the current branch. e.g main\ngit push -u origin main\n\n// Pull any changes from remote main branch\ngit pull origin main\n\ngit clone \"git_remote_repository_url\"\n\ngit reset \"index.html\"\n\n// Check current origin\ngit remote -v\n\n//Set a new origin.\ngit remote set-url origin \"git_remote_repository_url\"\n```\n\n## ✅ Git branch commands\n\n1. List of all branches.\n\n```bash\ngit branch -a\n```\n\n2. Show current branch.\n\n```bash\ngit branch --show-current\n```\n\n3. Create a new branch and switch to that branch\n\n```bash\ngit checkout -b \"new_branch_name\"\n```\n\n4. Rename current branch.\n\n```bash\ngit branch -m \"new_renamed_branch_name\"\n```\n\n5. Delete a branch. (locally)\n\n```bash\ngit branch -d \"deleted_branch_name\"\n```\n\n6. Delete a branch. (remote)\n\n```bash\ngit push origin -d \"\u003cBRANCH_NAME\u003e\"\n```\n\n7. Switch to a branch.\n\n```bash\ngit checkout \"branch_name\"\n```\n\n8. Merge a branch.\n\n```bash\ngit merge \"branch_name\"\n```\n\n## ✅ Git tag commands.\n\nUsing git tag commands you can easiliy mark stable version of a project. It creates an image of your git repository. To tag a branch, you need to checkout a stable branch. e.g `main`\n\n```bash\ngit checkout branch \"main\"\ngit tag v1.0\n```\n\n### Add message to the tag\n\n```bash\ngit tag -a v1.0 -m \"this is a stable 1.0 version of my project\"\n```\n\n### Show all the tags\n\n```bash\ngit tag\n```\n\n### Push a tag\n\n```bash\ngit push origin v1.0\n```\n\n### Push multiple tag\n\n```bash\ngit push origin v1.0 v1.1\n```\n\n### Push all tags\n\n```bash\ngit push --tags\n```\n\n### Delete a tag (local)\n\n```bash\ngit tag -d v1.0\n```\n\n### Delete multiple tag (local)\n\n```bash\ngit tag -d v1.0 v1.1\n```\n\n### Delete a tag (remote)\n\n```bash\ngit push origin -d v1.0\n```\n\n## ✅ Git commit log\n\nUsing the following commands, you can check all previous commits hash, commits date, author.\n\n### Check all logs\n\n```bash\ngit log\n```\n\n### Last 3 git logs\n\n```bash\ngit log -3\n```\n\n**Output**\n\n![git version check output](/previews/git_last_3_logs.jpg)\n\n## git logs in graphical mode\n\n```bash\ngit log --graph\n```\n\n**Output**\n\n![git version check output](/previews/git_log_graph_mode.jpg)\n\n## git logs in oneline mode\n\n```bash\ngit log --oneline\n```\n\n**Output**\n\n![git version check output](/previews/git_log_oneline.jpg)\n\n## Fix fatal: refusing to merge unrelated histories issue\n\n- Run the following command. (Check origin name, for mine it's the main)\n\n```bash\ngit pull origin main --allow-unrelated-histories\n```\n\n- After running this code a popup window will appear. Press 'wq' from keyboard.\n- It's done. Now you can push your code to the remote repository.\n\n## Remove a file/folder from git tracking\n\n```bash\ngit rm -r --cached 'FOLDER_NAME'\n```\n\n## Update last git commit message.\n\nIf you accidentally added a Git commit message or would like to update the last Git commit message, then use the following command:\n\n```bash\ngit commit --amend -m \"Updated commit message\"\n```\n\n### Bonus Commands For Mac\n\n1. Create a new directory\n\n```bash\nmkdir YOUR_DIR_NAME\n```\n\n2. Create an empty file.\n\n```bash\ntouch YOUR_FILE_NAME\n```\n\n3. Read A File.\n\n```bash\ncat YOUR_FILE_NAME\n```\n\n## Bonus Commands For Windows\n\n1. Create a directory\n\n```bash\nmkdir YOUR_DIR_NAME\n```\n\n2. List of folder and files in a directory.\n\n```bash\nls YOUR_DIR_NAME\n```\n\n3. Create an empty file.\n\n```bash\necho YOUR_FILE_NAME\n```\n\n## Acknowledgement\n\n- Md Mahbub Alam Khan\n\n- [bluewindlab.net](https://bluewindlab.net)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenioushk%2Fuseful-git-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxenioushk%2Fuseful-git-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenioushk%2Fuseful-git-commands/lists"}