{"id":19356315,"url":"https://github.com/mohaamadakbari/learning-git","last_synced_at":"2026-04-12T23:54:53.543Z","repository":{"id":261171362,"uuid":"883332149","full_name":"MohaamadAkbari/Learning-git","owner":"MohaamadAkbari","description":"A short summary of Git commands and Github options","archived":false,"fork":false,"pushed_at":"2025-04-27T00:38:45.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-27T01:27:46.713Z","etag":null,"topics":["git","github","learning"],"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/MohaamadAkbari.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}},"created_at":"2024-11-04T19:25:32.000Z","updated_at":"2025-04-27T00:38:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e4de924-7ee4-40a4-8717-7fd7eb95a89e","html_url":"https://github.com/MohaamadAkbari/Learning-git","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"b11f3253c911d7efe50b5da9c412df261f0cd3e1"},"previous_names":["mohaamadakbari/learning-git"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MohaamadAkbari/Learning-git","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohaamadAkbari%2FLearning-git","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohaamadAkbari%2FLearning-git/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohaamadAkbari%2FLearning-git/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohaamadAkbari%2FLearning-git/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MohaamadAkbari","download_url":"https://codeload.github.com/MohaamadAkbari/Learning-git/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohaamadAkbari%2FLearning-git/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268649819,"owners_count":24284195,"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-04T02:00:09.867Z","response_time":79,"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","github","learning"],"created_at":"2024-11-10T07:03:55.718Z","updated_at":"2026-04-12T23:54:53.503Z","avatar_url":"https://github.com/MohaamadAkbari.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Working with Git\n## Installation and Configuration\n\n* Use Homebrew to update git on Mac\n\n        $ brew install git\n\n* To find the git version on your system, use:\n\n        $ git --version\n\n* Configure global variables:\n\n        $ git config --global user.name \"username\"\n        $ git config --global user.email email_address\n        $ git config --global init.defaultBranch main\n\n* If you want to check your configuration settings:\n    \n        $ git config --list\n\n### Getting Help\n\n* If you want to get help while using Git:\n\n        $ git help \u003cverb\u003e\n        $ git \u003cverb\u003e help\n\n* A more concise help page:\n        $ git \u003cverb\u003e -h\n\n## Initializing a Repository\n\n* Go to the directory and command: \n\n        $ git init\n\n* This creates a new subdirectory named .git. Next, add the files into git:\n\n        $ git add \u003cfilename\u003e\n        $ git add .\n        $ git commit -m 'message'\n\n* Similarly to git add . you can write\n\n        $ git add --all\n        $ git add -A\n\n* Next, using the following command to see the action done.\n\n        $ git log\n        $ git log --oneline\n\n## Git Environment\n\n* **Commit Hash**: Each commit in Git has a unique ID called a commit hash.\n* **Branches**: Branches are alternate versions of your project. The current branch is indicated by the head.\n* **Git Environments**: Git has three main environments:\n    * **Working Environment**: Where files reflect the last commit.\n    * **Staging Environment**: A temporary area where files are queued before committing.\n    * **Commit** : The final state where changes are recorded with a new commit hash.\n\n* **File States**:\n    * **Tracked Files**: Files that existed in the previous commit.\n    * **Untracked Files**: New files added since the last commit.\n    * **Modified Files**: Tracked files that have been changed.\n    * **Staged Files**: Files moved to the staging environment.\n\n* **Git Status Command**: Used to check the current state of files and branches.\n\n        $ git status\n    \n    short status\n\n        $ git status -s \n\n* **Restore Command**: Used to discard changes or move files out of staging.\n\n    If a file is staged, command the following to make it back to modified but unstaged\n\n        $ git restore --staged file\n\n    If a file is modified, command the following to make it back to unmodified\n\n        $ git restore .\n    This command do nothing with untracked files.\n\n## Ignoring Files\n* **Purpose of Ignoring Files**: Prevents tracking of sensitive information like passwords, API keys, and local settings.\n* **.gitignore File**: Created at the root level of the project to specify files or patterns to ignore.\n* **Common Ignored Files**:\n\n        .DS_Store for macOS\n        .vscode/ folder for Visual Studio Code settings\n        node_modules for NPM projects\n        Custom files like authentication.js for tokens and keys\n        notes/\n        **/*-todo.md\n\n* **Git Behavior**: Ignored files are not uploaded to GitHub and are grayed out in Git status.\n* **Global Ignore File**: Can be set up for multiple projects using a config variable.\n\n        $ git config --global core.excludesfile [file]\n* **Clearing Cache**: Use the following command to clear cached files if .gitignore is updated after commits.\n\n        $ git rm -r --cached . \n        $ git add .\n        $ git commit -m 'clear cache'\n\n## Difference between Commits:\n\n* **Using git diff**: The following command shows the differences between files, highlighting changes such as deletions and additions.\n\n        $ git diff\n\n    If you want to compare staged changes to your last commit:\n        $ git diff --staged\n\n* **Handling large changes**: For extensive changes, using Visual Studio Code's source control editor can make it easier to view and manage differences.\n\n* **Comparing commits**: You can compare a file to its state at any previous commit using git diff and the commit hash.\n\n* **Git Lens extension**: For frequent comparisons between branches and checkpoints, the Git Lens extension in Visual Studio Code is recommended.\n\n## Deleting and Renaming Files\n\n#### Deleting a file\n\n* **Direct Deletion**: You can delete a file directly from the file system or using Visual Studio Code. Git will track this deletion and you need to stage and commit it.\n\n* **Git RM Command**: Using the following command, the file is deleted and the deletion is automatically staged.\n\n        $ git rm \u003cfile\u003e, \n\n#### Restoring Files:\n* **Git Restore Command**: Use the following command to bring back a deleted file. For staged deletions, use git restore --staged \u003cfile\u003e.\n\n        $ git restore \u003cfile\u003e \n\n#### Renaming Files:\n\n* **Direct Renaming**: Renaming a file directly in the file system is tracked by Git as a deletion of the old file and addition of the new file.\nGit MV Command: Use the following command to rename a file, which stages the change automatically.\n\n        $ git mv \u003cold_name\u003e \u003cnew_name\u003e \n\n## Changing History\n\n* **Amending Commits**: You can amend the last commit to include additional changes without creating a new commit, keeping your commit history clean.\n* To add changes to the last commit, command with new messages or no new messages,\n\n        $ git commit --amend\n        $ git commit --amend -m 'New commit message'\n        $ git commit --amend --no-edit\n\n\n* **Resetting**: The git reset command allows you to move back to a previous commit, either keeping changes (--soft) or discarding them (--hard).\n\n        $ git restore \u003ccommit\u003e\n        $ git restore --hard \u003ccommit\u003e\n\n* **Rebasing**: Rebasing lets you take commits from one branch and apply them to another, effectively rewriting the commit history to make it cleaner or to reorder commits.\n\n        $ git rebase \u003cbranch\u003e/\u003ccommit\u003e\n        $ git rebase --interactive \u003cbranch\u003e/\u003ccommit\u003e\n        $ git rebase - i HEAD-#\n        $ git rebase -i --root\n\n## Branches\n\n* **Creating Branches**: Branches allow you to create different versions of your code to experiment with new features without affecting the stable version. \n* To see current branches, command\n\n        $ git branch\n\n* To copy a new brach command git switch -c or the older git checkout -b to create a new branch.\n\n        $ git switch -c NAME\n        $ git checkout -b NAME\n\n* **Managing Branches**: You can switch between branches using git switch and view all branches with git branch. After making changes in a branch, use git add and git commit to save those changes.\n\n* **Merging Branches**: To merge changes from one branch into another, switch to the target branch and use git merge. \n\n        $ git merge \u003cbranch\u003e\n\n* **Deleting Branches**: After merging, it's a good practice to delete the feature branch using git branch -d.\n\n        $ git branch --delete NAME\n        $ git branch -d NAME\n        $ git branch -D \n\n### Git FLow\n* Developers do the following flow on real projects:\n    * Feature/fix branch\n    * Make changes\n    * Merge to master\n    * Delete old branch\n\n## Merging Conflicts\n\n* **Understanding Merge Conflicts**: Merge conflicts occur when changes are made to the same part of a file in different branches. This typically happens when multiple people are working on the same project.\n\n* **Resolving Conflicts** : The video demonstrates how to resolve merge conflicts using Visual Studio Code, which provides helpful indicators to choose between conflicting changes.\n\n* **Best Practices**: It’s important to decide which changes to keep and manually adjust the code to resolve conflicts, ensuring that the final version is correct and consistent.\n\n## Stashing and Cleaning\n\n* **Git Stash**: Temporarily stores changes so you can work on something else without losing your current progress. Commands include git stash, git stash list, git stash apply, and git stash pop.\n\n* To store changes, use the command\n\n        $ git stash\n\n* To see the stored changes, use the command\n\n        $ git stash list\n\n* The following command allows you to apply a stash set of changes.\n\n        $ git stash apply \u003cindex\u003e\n\n* The following command remove the git stash from the list\n\n        $ git stash pop\n\n* **Git Clean**: Removes untracked files and directories from your working directory. Use git clean -n to preview what will be removed and git clean -df to execute the clean.\n\n        $ git clean -n\n        $ git clean -d\n        $ git clean -f\n\n# GitHub\n\n* GitHub as a Collaborative Platform: GitHub is an online service that allows developers to work together, often referred to as a social coding website.\n\n* Core Functions: It provides tools for tracking changes, assigning issues, and deploying code. It also includes project management tools like Kanban boards.\n\n* Setting Up and Using GitHub: Key actions include setting up a remote repository, pushing local changes to GitHub, and fetching and pulling changes from the remote repository.\n\n## Pushing to GitHub\n\n* Setting Up Remotes: Use git remote add \u003cname\u003e \u003cURL\u003e to connect your local project to a remote repository. Commonly, the remote name is \"origin\".\n\n        $ git remote add \u003cname\u003e \u003cURL\u003e\n\n\n* Pushing Changes: Use git push to move files from your local machine to GitHub. The first push requires the -u option to set the upstream branch.\n\n        $ git push -u origin main\n        $ git push --all\n        $ git branch --set-upstream-to \u003corigin/remote-branch\u003e\n\n* Managing Remotes: You can list, remove, and rename remotes using commands like git remote -v, git remote remove \u003cname\u003e, and git remote rename \u003cold-name\u003e \u003cnew-name\u003e.\n\n## Github Options\n\n* **Branch Management**: You can manage branches directly in GitHub, including creating, editing, and deleting branches.\n\n* **File Management**: GitHub allows you to edit files, add new files, and organize them into directories.\n\n* **Tags and Topics**: You can add tags to your projects to make them easier to find and add topics to help others discover your work.\n\n* **Issues and Pull Requests**: Use issues to track tasks and pull requests to approve changes made by others.\n\n* **GitHub Pages**: Host your website for free using GitHub Pages, which allows you to serve static sites directly from a GitHub repository.\n\n## Github Workflow\n\n* **Branch-Based Workflow**: GitHub Flow is a branch-based workflow where the main branch contains the current version of the code. Changes are made in feature branches, which are copies of the main branch.\n\n* **Feature Branches**: To modify the code, you create a feature branch. This allows you to work on new features or changes without affecting the main branch.\n\n* **Commits and Pushes**: Changes are made in the feature branch, committed, and then pushed back to the feature branch. Each commit should be an isolated and complete change.\n\n## Pull Requests\n\n* **Pull Requests**: When ready, you create a pull request to merge changes from the feature branch back into the main branch. This allows for feedback and code review from others.\n\n* **Code Review and Feedback**: Reviewers can leave comments, feedback, and suggestions on the pull request. This collaborative process helps ensure code quality.\n\n* **Merging Changes**: Once the pull request is approved, the changes are merged into the main branch. This process may involve reviewing differences between the feature branch and the main branch.\n\n* **Deleting Feature Branches**\n: After merging, the feature branch can be deleted to indicate the process is complete.\n\n## Pull Requests Features\n\n* **Creating a Pull Request**: You can initiate a pull request directly on GitHub by editing a file, previewing changes, and proposing the changes to create a new branch.\n\n* **Managing Pull Requests**: Pull requests allow you to have conversations, add comments, and assign reviewers to discuss and approve changes before merging them into the main branch.\n\n* **Project Management Features**: GitHub provides tools like labels, milestones, and issue linking to manage and track pull requests effectively.\n\n* **Comparing Branches**: You can compare different branches to see changes before and after a pull request, allowing flexibility in viewing various branches.\n\n* **Draft Pull Requests**: These serve as placeholders for work-in-progress, enabling discussions and comments before the final review.\n\n* **Review Process**: Pull requests facilitate conversations, comments, and reviews, with options to assign reviewers and use tools like GitGuardian for security checks.\n\n* **Resolving Comments**: You can address comments made during the review by editing the code and marking the conversation as resolved.\n\n* **Pushing Updates**: After making changes, commit and sync your updates to the repository to reflect the resolved issues.\n\n* **Merging Pull Requests**: Once all comments are addressed and changes are committed, you can merge the pull request to finalize the review process.\n\n\n## CodeOwners\n\n* **Creating a CODEOWNERS File**: You can create a CODEOWNERS file in your repository to assign ownership of files and directories to specific users.\n\n* **Branch Protection**: You can set branch protection rules to require pull requests and approvals before merging changes, enhancing security and control.\n\n\n* **Automatic Notifications**: The assigned owners will automatically receive notifications for any changes, ensuring they are involved in the review process.\n\n## Organizing Projects\n\n* **Collaborators**: You can invite others to work on your project, enhancing collaboration.\n\n* **Issues**: Create and manage issues to track tasks and bugs, using labels and milestones for better organization.\n\n* **Projects**: Use GitHub projects to visualize and manage the progress of your work, with options like Kanban boards for effective project management.\n\n## Repository Insights\n\n* **Insights Tab**: Provides detailed information about the repository, including activity, contributors, and community standards.\n\n* **Graphs and Metrics**: Displays various metrics such as merge pull requests, additions and deletions, and traffic sources.\n\n* **Community Standards**: Shows how the repository compares to GitHub's recommended community standards and allows you to create necessary files.\n\n* **Dependency Management**: Features like Dependabot help track and update project dependencies.\n\n* **Forks and Stars**: Information on forks, stars, and watchers, indicating the repository's popularity and engagement.\n\n## GitHub Shortcuts\n\n* **Question Mark (?)**: Displays a list of most shortcuts, which are context-sensitive.\n\n* **Slash (/)**: Used for searching within repositories, also context-sensitive.\n\n* **Command Palette**: Accessed with Command + K on Mac or Control + K on Windows, providing a powerful search and navigation tool.\n\n* **Period (.)**: Opens the repository in a lightweight editor at github.dev.\n\n* **Feature Preview**: Allows you to enable and test upcoming GitHub features.\n\n## Synching GitHub and local repository\n\n* **git clone**: Copies a GitHub repository to your local hard drive.\n\n        $ git clone \u003cURL\u003e\n\n* **git fetch**: Downloads information from the remote repository to your local repo without merging it.\n\n        $ git fetch\n\n* **git pull**: Combines fetching and merging data from the remote repository to your local version.\n\n        $ git pull\n\n* **Branch Management**: Commands like git branch -a and using Visual Studio Code to manage and switch between branches.\n\n* **Releases**: Creating official versions of your project using GitHub releases for specific versions of your code.\n\n* **Automatic Notifications**: The assigned owners will automatically receive notifications for any changes, ensuring they are involved in the review process.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohaamadakbari%2Flearning-git","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohaamadakbari%2Flearning-git","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohaamadakbari%2Flearning-git/lists"}