{"id":20453525,"url":"https://github.com/saifaustcse/git-workflow-and-commands","last_synced_at":"2025-08-21T15:12:46.780Z","repository":{"id":88560915,"uuid":"318475925","full_name":"saifaustcse/git-workflow-and-commands","owner":"saifaustcse","description":"Git workflow with basic commands","archived":false,"fork":false,"pushed_at":"2021-08-27T04:31:26.000Z","size":295,"stargazers_count":15,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-13T03:41:48.241Z","etag":null,"topics":["git","git-basics","git-commands","git-workflow"],"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/saifaustcse.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":"2020-12-04T10:05:59.000Z","updated_at":"2024-06-23T11:17:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"9fa64f87-ce6c-4358-b65b-ecf6c64cbdd1","html_url":"https://github.com/saifaustcse/git-workflow-and-commands","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/saifaustcse/git-workflow-and-commands","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saifaustcse%2Fgit-workflow-and-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saifaustcse%2Fgit-workflow-and-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saifaustcse%2Fgit-workflow-and-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saifaustcse%2Fgit-workflow-and-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saifaustcse","download_url":"https://codeload.github.com/saifaustcse/git-workflow-and-commands/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saifaustcse%2Fgit-workflow-and-commands/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271500298,"owners_count":24770371,"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-08-21T02:00:08.990Z","response_time":74,"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","git-basics","git-commands","git-workflow"],"created_at":"2024-11-15T11:13:03.355Z","updated_at":"2025-08-21T15:12:46.768Z","avatar_url":"https://github.com/saifaustcse.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## Git Workflow and Commands\n\nThough there are 1000’s of articles about git, I have written this article is in order to document what I understood and how I understood which may help others as well. Here I tried to avoid complexity and wanted to keep it simple and\nfollowed the easiest process.\n\n## Give a Star! :star:\n\nIf you like or are using this project to learn or start your solution, please give it a star. Thanks!\n\n## Workflow\n\n   \u003cdiv  style=\"text-align: center;\"\u003e\n       \u003cimg src=\"https://github.com/saifaustcse/Git-workflow-and-commands/blob/main/images/workflow.png\" width=\"750\" height=\"450\"\u003e\n   \u003cdiv\u003e\n\n## Commands\n\n### Configuration\n\nGit config that lets you get and set configuration variables that control all aspects of how Git looks and operates.\n\n    # Display the current Git configuration.\n    $ git config --list\n\n    # Set the user information when submitting code.\n    git config --global user.name \"Saiful Islam\"\n    git config --global user.email \"saifaustcse26@gmail.com\"\n\n    # Check\n    git config --global user.name\n    git config --global user.email\n\n### Manage Repository\n\nCreate a Repository in git hub/git lab then Clone the Repository\n\n-   [How to create git hub repository.](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/create-a-repo)\n\n\n### Download an existing git repository to your local computer with its entire code history.\n    $ git clone [url]\n\n\n\n### Adding files and folder (Workspace --\u003e Staging)\n\n    # Add the specified file from the current directory to the staging.\n    # Start tracking an untracked file\n    $ git add [file1] [file2] [fileN]\n\n    # Add the specified directory from the current directory to the staging, including subdirectories.\n    # Start tracking an untracked directory\n    $ git add [dir]\n\n    # Add all files (tracked or untracked) from the current directory to the staging.\n    # Start tracking a untracked file\n    # Update the changes of tracked file from the current directory to the staging.\n    $ git add .\n\n### Commit changes (Staging --\u003e Repository)\n\n    # Submit the code from the staging to the Repository with a message\n    $ git commit -m [message]\n\n    # Submit the specified file from the staging to the Repository.\n    $ git commit [file1] [file2] [fileN] -m [message]\n\n    # Display all diff information when submitting.\n    $ git commit -v\n\n    # update and replace the most recent commit with a new commit\n    $ git commit --amend\n\n### Commit changes (Workspace --\u003e Staging --\u003e Repository)\n\n    # Submit the changes of all tracked files after the last commit.\n    $ git commit -am [message]\n\n    # For untracked file\n    $ git add .\n    $ git commit -am [message]\n\n### Remote synchronization from Repository(Repository --\u003e Remote)\n\n    # Push the current branch to the Remote Repository.\n    $ git push origin [branch]\n\n### Repository synchronization from remote (Repository \u003c-- Remote)\n\n    # Download specific branch.\n    $ git fetch origin [branch]\n\n    # Download all remote branches.\n    $ git fetch --all\n\n### Workspace synchronization from Repository (Workspace \u003c-- Repository)\n\n    # merge the specified branch to the current branch.\n    $ git merge [branch]\n\n    # merge a branch into a target branch\n    $ git merge [source branch] [target branch]\n\n\n### Workspace synchronization from remote (Workspace \u003c-- Repository \u003c-- Remote)\n\n    # Retrieve the changes to the Remote Repository and merge with the local branch (fetch+merge)\n    $ git pull origin [branch]\n\n### Branching\n\n    # List all local branches. (the asterisk denotes the current branch)\n    $ git branch\n\n    # List all remote branches.\n    $ git branch -r\n\n    # List all local branches and remote branches.\n    $ git branch -a\n\n    # Create a new branch, but still stay in the current branch.\n    $ git branch [branch-name]\n\n    # Create a new branch and switch to the branch.\n    $ git checkout -b [branch]\n\n    # Switch to the specified branch.\n    $ git checkout [branch-name]\n\n    # Switch to the previous branch.\n    $ git checkout -\n\n    # Delete the branch.\n    $ git branch -d [branch-name]\n\n    # Delete the remote branch.\n    $ git push origin --delete [branch-name]\n    $ git branch -dr [remote/branch]\n\n\n### Inspection\n\n    # Display the changed files.\n    $ git status\n\n    # Display the version history of the current branch.\n    $ git log\n\n    # Display all commits (Custom Filtering)\n    $ git log --all\n\n    # Display the 5 most recent commits (Custom Filtering)\n    $ git log -5\n\n    # View Commit History in ASCII Graph\n    $ git log --graph\n\n    # Display Just One Line Per Commit\n    $ git log --oneline\n\n    # Display Just One Line Per Commit with message (Custom Formatting)\n    $ git log --pretty=oneline\n\n    # Display all the users who have committed, sorted by number of commits.\n    $ git shortlog -sn\n\n    # Show the latest commits of the current branch.\n    $ git reflog\n\nFor more details:\n\n-   [The-official-Git-site](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History)\n-   [Atlassian](https://www.atlassian.com/git/tutorials/git-log)\n-   [Thegeekstuff](https://www.thegeekstuff.com/2014/04/git-log/)\n\n### Discard changes from Workspace\n\n    # Discard changes from the specified file of the Workspace.\n    $ git checkout [file]\n\n    # Discard all changes of the Workspace.\n    $ git checkout .\n\n### Revoke/Undo from Staging (Workspace \u003c-- Staging)\n\n    # If unwanted file were added to the staging area but not yet committed.\n    # Restore specified file from the Staging to the Workspace.\n    # Changes will stay in workspace.\n    $ git reset [file]\n\n    # Restore all files from the Staging to the Workspace.\n    # Changes will stay in workspace.\n    $ git reset\n    $ git reset HEAD .\n\n    # Restore all files from the Staging to the Workspace.\n    # All chnages will be discard.\n    $ git reset --hard\n\n### Revoke/Undo from Repository (Workspace \u003c-- Staging \u003c-- Repository)\n\n    # Restore all files from the Repository to the Workspace.\n    # All changes will stay on Workspace.\n    # Undo the last commit.\n    $ git reset HEAD~1\n    $ git reset --mixed HEAD~1\n\n    # Restore all files from the Repository to the Staging.\n    # All changes will stay on Staging.\n    # Undo the last commit.\n    $ git reset --soft HEAD~1\n\n    # Restore all files from the Repository to the Workspace.\n    # All chnages will be discard.\n    # Undo the last commit.\n    $ git reset --hard HEAD~1\n\n### Revoke/Undo from Remote (Workspace \u003c-- Staging \u003c-- Repository \u003c-- Remote)\n\n    # Create a new commit to undo the specified commit.\n    # All changes of the latter will be offset by the former and applied to the current branch.\n    # This is safe\n    $ git revert [commit]\n    $ git commit -m \"message\"\n    $ git push origin [branch]\n\n### Removing files or folders (Workspace --\u003e Staging --\u003e Repository --\u003e Remote)\n\n    # Manually delete the files or folders from Workspace\n    # The following command will permanently remove the files or folders\n    $ git add .\n    $ git commit -m \"message\"\n    $ git push origin [branch]\n\n\n### Stash\n\n    # Temporarily saves or stashes changes of working copy and and move them in later.\n    $ git stash\n\n    # Saving Stashes with the message\n    $ git stash save \"\u003cStashing Message\u003e\"\n\n    # Check the Stored Stashes\n    $ git stash list\n\n    # Restored the changes of latest stash from stashes\n    # Remove the latest stash from stashes\n    $ git stash pop\n\n    # Restored the changes of latest stash from stashes\n    $ git stash apply\n\n    # Restored the changes of specific stash from stashes\n    $ git stash apply \u003cstash id\u003e\n\n    # Remove the latest stash from stashes\n    $ git stash drop\n\n    # Remove the specific stash from stashes\n    $ git stash drop \u003cstash id\u003e\n\n    # Remove all stashes\n    $ git stash clear\n\n### Tag\n\n     # List all tags.\n     $ git tag\n\n     # Create a new tag in the current commit.\n     $ git tag [tag_name]\n\n     # Create a new tag in the specified commit.\n     $ git tag [tag] [commit]\n\n     # Delete the local tag.\n     $ git tag -d [tag_name]\n\n     # Push the specified tag to remote.\n     $ git push origin [tag_name]\n\n     # Push all tags to remote.\n     $ git push origin --tag\n\n     # Delete the remote tag.\n     $ git push origin :refs/tags/[tag_name]\n\n     # View the tag information.\n     $ git show [tag_name]\n\n     # Create a new branch pointing to a certain tag\n     $ git checkout -b [branch] [tag]\n\n     Notes:\n     # When you want to create a release point for a stable version\n     # Tag is nothing but a reference name of a commit\n     # Multiple tag name is possible for same commit\n\n### cherry-pick\n\n      # Select a commit to be merged into the current branch.\n      $ git cherry-pick [commit]\n\n### Checkout vs Reset vs Revert\n\n-   [Atlassian](https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting)\n-   [Medium](https://medium.com/@manivel45/git-merge-vs-rebase-reset-vs-revert-vs-checkout-dd5674d0e18a)\n-   [opensource](https://opensource.com/article/18/6/git-reset-revert-rebase-commands)\n\n### Merging vs. Rebasing\n\n-   [Atlassian](https://www.atlassian.com/git/tutorials/merging-vs-rebasing)\n\n# References\n\nI have followed many articles but among them, the following articles are really helpful. Those articles helped me a lot and also encourage me to write this article according to my understanding.\n\n-   [The-official-Git-site](https://git-scm.com/book/en/v2)\n-   [Atlassian](https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html)\n-   [Git-most-frequently-used-commands](https://medium.com/analytics-vidhya/git-most-frequently-used-commands-9df9f200c235)\n-   [Ercankaracelik](https://ercankaracelik.wordpress.com/2018/12/08/basic-git-commands/)\n-   [Tutorialdocs](https://www.tutorialdocs.com/article/git-basic-command-list.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaifaustcse%2Fgit-workflow-and-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaifaustcse%2Fgit-workflow-and-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaifaustcse%2Fgit-workflow-and-commands/lists"}