{"id":23109468,"url":"https://github.com/msadeqsirjani/mastergit","last_synced_at":"2026-04-24T21:32:27.053Z","repository":{"id":142797963,"uuid":"412112452","full_name":"msadeqsirjani/MasterGit","owner":"msadeqsirjani","description":"An interactive git training meant to teach you how git works, not just which commands to execute","archived":false,"fork":false,"pushed_at":"2021-09-30T19:41:55.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T22:03:25.733Z","etag":null,"topics":["git","github","version-control"],"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/msadeqsirjani.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-09-30T15:08:54.000Z","updated_at":"2023-02-05T05:49:33.000Z","dependencies_parsed_at":"2023-05-31T05:00:19.708Z","dependency_job_id":null,"html_url":"https://github.com/msadeqsirjani/MasterGit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/msadeqsirjani/MasterGit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msadeqsirjani%2FMasterGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msadeqsirjani%2FMasterGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msadeqsirjani%2FMasterGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msadeqsirjani%2FMasterGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msadeqsirjani","download_url":"https://codeload.github.com/msadeqsirjani/MasterGit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msadeqsirjani%2FMasterGit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"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":["git","github","version-control"],"created_at":"2024-12-17T01:36:43.642Z","updated_at":"2026-04-24T21:32:27.040Z","avatar_url":"https://github.com/msadeqsirjani.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\u003cimg\n  src=\"/img/git.png\"\n  width=\"70\"\n  align=\"right\"\n/\u003e\n\n# Useful Git Commands\n\n\n## About it\n\u003e Have you recently started using Git? This should give you the base commands you need to perform the most common actions in Git. If you find a command that is not here, or could be explained better, please don't hesitate in * [Contributing](#contributing). Cheers!\n\n## Table of contents\n\n* [Install git](#install-git)\n* [Setting up git](#setting-up-git)\n* [Applying colour to git ](#applying-colour-to-git)\n* [Initializing a repository in an existing directory](#initializing-a-repository-in-an-existing-directory)\n* [Checking the status of your files](#checking-the-status-of-your-files)\n* [Staging files](#staging-files)\n* [Stashing files](#stashing-files)\n* [Committing files](#committing-files)\n* [Branching and merging](#branching-and-merging)\n* [Resetting](#resetting)\n* [Git remote](#git-remote)\n* [Git grep](#git-grep)\n* [Git blame](#git-blame)\n* [Git log](#git-log)\n* [Checking what you are committing](#checking-what-you-are-committing)\n* [Useful Commands](#useful-commands)\n* [Useful Alias](#useful-alias)\n* [Contributing](#contributing)\n\n#### Git\n\nGit is a distributed version control system, very easy to learn and supper fast!\n\n#### Install Git\n\nThere are a few different ways to install git (from source or for Linux) but the purpose of this page is to focus on git commands, so I am going to assume you are installing git on a Mac.\n\nTo view other ways of installing it visit the [Git official site](http://git-scm.com/book/en/Getting-Started-Installing-Git)\n\nClick [here](http://git-scm.com/download/mac) to download and install Git\n\n##### Setting up git\n\n```sh\n$ git config --global user.name \"User Name\"\n\n$ git config --global user.email \"email\"\n```\n\n##### Applying colour to git\n\n```sh\n$ git config --global color.ui true\n```\n\n##### Initializing a repository in an existing directory\n\nIf you’re starting to track an existing project in Git, you need to go to the project’s directory and type:\n\n```sh\n$ git init\n```\nThis creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton. At this point, nothing in your project is tracked yet.\n\nTo start version-controlling existing files you should start by tracking those files and do an initial commit. To accomplish that you should start with a few  `$ git add` that specifies the files you want to track followed by a commit.\n\n```sh\n$ git add \u003cfile\u003e\n$ git add README\n$ git commit -m 'Initial project version'\n```\n#### Checking the status of your files\n\nThe main tool you use to determine which files are in which state is the `$ git status` command. If you run this command directly after a clone, you should see something like this:\n\n```sh\n$ git status\n# On branch master\nnothing to commit (working directory clean)\n```\n\nIf you add a new file to your project, and the file didn't exist before, when you run a `$ git status` you should see your untracked file like this:\n\n```sh\n$ git status\n# On branch master\n# Untracked files:\n#   (use \"git add \u003cfile\u003e...\" to include in what will be committed)\n#\n#   README\nnothing added to commit but untracked files present (use \"git add\" to track)\n```\n\n#### Staging files\n\nAfter initializing a git repository in the chosen directory, all files will now be tracked. Any changes made to any file will be shown after a `$ git status` as changes not staged for commit.\n\nTo stage changes for commit you need to add the file(s) - or in other words, stage file(s).\n\n```sh\n# Adding a file\n$ git add filename\n\n# Adding all files\n$ git add -A\n\n# Adding all files changes in a directory\n$ git add .\n\n# Choosing what changes to add (this will got through all your changes and you can 'Y' or 'N' the changes)\n$ git add -p\n```\n\n#### Stashing files\n\nGit stash is a very useful command, where git will 'hide' the changes on a dirty directory - but no worries you can re-apply them later. The command will save your local changes away and revert the working directory to match the HEAD commit.\n\n```sh\n# Stash local changes\n$ git stash\n\n# Stash local changes with a custom message\n$ git stash save \"this is your custom message\"\n\n# Re-apply the changes you saved in your latest stash\n$ git stash apply\n\n# Re-apply the changes you saved in a given stash number\n$ git stash apply stash@{stash_number}\n\n# Drops any stash by its number\n$ git stash drop stash@{0}\n\n# Apply the stash and then immediately drop it from your stack\n$ git stash pop\n\n# 'Release' a particular stash from your list of stashes\n$ git stash pop stash@{stash_number}\n\n# List all stashes\n$ git stash list\n\n# Show the latest stash changes\n$ git stash show\n\n# See diff details of a given stash number\n$ git diff stash@{0}\n```\n\n#### Committing files\n\nAfter adding/staging a file, the next step is to commit staged file(s)\n\n```sh\n# Commit staged file(s)\n$ git commit -m 'commit message'\n\n# Add file and commit\n$ git commit filename -m 'commit message'\n\n# Add file and commit staged file\n$ git commit -am 'insert commit message'\n\n# Amending a commit\n$ git commit --amend 'new commit message' or no message to maintain previous message\n\n# Squashing commits together\n$ git rebase -i\nThis will give you an interface on your core editor:\n# Commands:\n#  p, pick = use commit\n#  r, reword = use commit, but edit the commit message\n#  e, edit = use commit, but stop for amending\n#  s, squash = use commit, but meld into previous commit\n#  f, fixup = like \"squash\", but discard this commit's log message\n#  x, exec = run command (the rest of the line) using shell\n\n# Squashing commits together using reset --soft\n$ git reset --soft HEAD~number_of_commits\n$ git commit\n** WARNING: this will require force pushing commits, which is OK if this is on a branch before you push to master or create a Pull Request.\n```\n\n#### Branching and merging\n\n```sh\n# Switching between branches\n$ git switch branchname\n\n# Creating a local branch\n$ git checkout -b branchname\n\n# Creating a local branch\n$ git switch -c branchname\n\n# Switching between 2 branches (in fact, this would work on terminal as well to switch between 2 directories - $ cd -)\n$ git checkout -\n\n# Pushing local branch to remote\n$ git push -u origin branchname\n\n# Deleting a local branch - this won't let you delete a branch that hasn't been merged yet\n$ git branch -d branchname\n\n# Deleting a local branch - this WILL delete a branch even if it hasn't been merged yet!\n$ git branch -D branchname\n\n# Remove any remote refs you have locally that have been removed from your remote (you can substitute \u003corigin\u003e to any remote branch)\n$ git remote prune origin\n\n# Show all remote branchs\n$ git ls-remote\n\n# Viewing all branches, including local and remote branches\n$ git branch -a\n\n# Viewing all branches that have been merged into your current branch, including local and remote\n$ git branch -a --merged\n\n# Viewing all branches that haven't been merged into your current branch, including local and remote\n$ git branch -a --no-merged\n\n# Viewing local branches\n$ git branch\n\n# Viewing remote branches\n$ git branch -r\n\n# Viewing branches related to origin branchs and last commit description\n$ git branch -vv\n\n# Rebase master branch into local branch\n$ git rebase origin/master\n\n# Pushing local branch after rebasing master into local branch\n$ git push origin +branchname\n\n# Removing remote origin branch\n$ git push --delete origin branchname\n```\n\n#### Fetching and checking out remote branches\n\n```sh\n# This will fetch all the remote branches for you.\n$ git fetch origin\n\n# With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:\n$ git checkout -b test origin/test\n\n# Deleting a remote branch\n$ git branch -rd origin/branchname\n$ git push origin --delete branchname  or  $ git push origin:branchname\n```\n\n#### Merging branch to trunk/master\n\n```sh\n# First checkout trunk/master\n$ git checkout trunk/master\n\n# Now merge branch to trunk/master\n$ git merge branchname\n\n# To cancel a merge\n$ git merge --abort\n```\n\n#### Updating a local repository with changes from a Github repository\n\n```sh\n$ git pull origin master\n```\n\n#### Tracking existing branch\n\n```sh\n$ git branch --set-upstream-to=origin/foo foo\n\n$ git branch --track origin/brancname local-tracking-branch\n```\n\n#### Resetting\n\n```sh\n# Mixes your head with a give sha\n# This lets you do things like split a commit\n$ git reset --mixed [sha]\n\n# Upstream master\n$ git reset HEAD origin/master -- filename\n\n# The version from the most recent commit\n$ git reset HEAD -- filename\n\n# The version before the most recent commit\n$ git reset HEAD^ -- filename\n\n# Move head to specific commit\n$ git reset --hard sha\n\n# Reset the staging area and the working directory to match the most recent commit. In addition to unstaging changes, the --hard flag tells Git to overwrite all changes in the working directory, too.\n$ git reset --hard\n```\n\n#### Git remote\n\n```sh\n# Show where 'origin' is pointing to and also tracked branches\n$ git remote show origin\n\n# Show where 'origin' is pointing to\n$ git remote -v\n\n# Change the 'origin' remote's URL\n$ git remote set-url origin https://github.com/user/repo.git\n\n# Add a new 'origin'\n# Usually use to 'rebase' from forks\n$ git remote add [NAME] https://github.com/user/fork-repo.git\n```\n\n#### Git grep\n\n```sh\n# 'Searches' for parts of strings in a directory\n$ git grep 'something'\n\n# 'Searches' for parts of strings in a directory and the -n prints out the line numbers where git has found matches\n$ git grep -n 'something'\n\n# 'Searches' for parts of string in a context (some lines before and some after the grepped term)\n$ git grep -C\u003cnumber of lines\u003e 'something'\n\n# 'Searches' for parts of string and also shows lines BEFORE the grepped term\n$ git grep -B\u003cnumber of lines\u003e 'something'\n\n# 'Searches' for parts of string and also shows lines AFTER the grepped term\n$ git grep -A\u003cnumber of lines\u003e 'something'\n```\n\n#### Git blame\n\n```sh\n# Show alteration history of a file with the name of the author\n$ git blame [filename]\n\n# Show alteration history of a file with the name of the author \u0026\u0026 SHA\n$ git blame [filename] -l\n```\n\n#### Git log\n\n```sh\n# Show a list of all commits in a repository. This command shows everything about a commit, such as commit ID, author, date and commit message.\n$ git log\n\n# List of commits showing commit messages and changes\n$ git log -p\n\n# List of commits with the particular expression you are looking for\n$ git log -S 'something'\n\n# List of commits by author\n$ git log --author 'Author Name'\n\n# Show a list of commits in a repository in a more summarised way. This shows a shorter version of the commit ID and the commit message.\n$ git log --oneline\n\n# Show a list of commits in a repository since yesterday\n$ git log --since=yesterday\n\n# Shows log by author and searching for specific term inside the commit message\n$ git log --grep \"term\" --author \"name\"\n```\n\n#### Checking what you are committing\n\n```sh\n# See all (non-staged) changes done to a local repo\n$ git diff\n\n# See all (staged) changes done to a local repo\n$ git diff --cached\n\n# Check what the changes between the files you've committed and the live repo\n$ git diff --stat origin/master\n```\n\n#### Useful commands\n\n```sh\n# Check if a sha is in production\n$ git tag --contains [sha]\n\n# Number of commits by author\n$ git shortlog -s --author 'Author Name'\n\n# List of authors and commits to a repository sorted alphabetically\n$ git shortlog -s -n\n\n# List of commit comments by author\n$ git shortlog -n --author 'Author Name'\n# This also shows the total number of commits by the author\n\n# Number of commits by contributors\n$ git shortlog -s -n\n\n# Undo local changes to a File\n$ git checkout -- filename\n\n# Shows more detailed info about a commit\n$ git cat-file sha -p\n\n# Show number of lines added and removed from a repository by an author since some time in the past.\n$ git log --author=\"Author name\" --pretty=tformat: --numstat --since=month | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\\n\", add, subs, loc }'\n```\n\n#### Useful alias\nTo add an alias simply open your .gitconfig file on your home directory and include the alias code\n\n```sh\n# Shows the log in a more consisted way with the graph for branching and merging\nlg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)\u003c%an\u003e%Creset' --abbrev-commit\n```\n\n### Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -m 'Add some feature'`\n4. Push to the branch: `git push -u origin my-new-feature`\n5. Submit a pull request - cheers!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsadeqsirjani%2Fmastergit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsadeqsirjani%2Fmastergit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsadeqsirjani%2Fmastergit/lists"}