Skip to content

Latest commit

 

History

History
53 lines (46 loc) · 4.47 KB

File metadata and controls

53 lines (46 loc) · 4.47 KB

What is GitHub and Git?

GitHub is a web-based platform that uses Git for version control and provides additional features like issue tracking, pull requests, and project management tools. It allows developers to host their Git repositories online, making it easier to collaborate on projects. Git is a distributed version control system that allows multiple developers to work on a project simultaneously without overwriting each other's changes. It tracks changes in source code during software development, enabling collaboration and version management.

Key concepts of Git and GitHub

  • Repository (Repo): A storage space for your project, which can be local (on your computer) or remote (on GitHub).
  • Commit: A snapshot of your project at a specific point in time. It includes a message describing the changes made.
  • Push: Uploading local changes to a remote repository on GitHub.
  • Pull: Fetching and integrating changes from a remote repository into your local repository.
  • Branch: A separate line of development in a repository. The default branch is usually called main or master.
  • Merge: Combining changes from one branch into another, typically from a feature branch into the main branch.
  • Clone: Creating a local copy of a remote repository.
  • Fork: Creating a personal copy of someone else's repository on GitHub, allowing you to make changes without affecting the original project.
  • Pull Request (PR): A request to merge changes from one branch into another, often used for code review and discussion before merging.
  • Issue: A way to track bugs, enhancements, or tasks related to a project. Issues can be assigned to team members and labeled for organization.
  • Tag: A marker for a specific point in the repository's history, often used to mark releases or important milestones.

Basic Git Commands

  • git init: Initialize a new Git repository.
  • git clone <repository-url>: Clone a remote repository to your local machine.
  • git add <file>: Stage changes to a file for the next commit.
  • git commit -m "commit message": Commit staged changes with a descriptive message.
  • git status: Check the status of your repository, including staged and unstaged changes.
  • git push: Push local commits to the remote repository.
  • git pull: Fetch and merge changes from the remote repository into your local branch.
  • git branch: List all branches in the repository.
  • git checkout <branch>: Switch to a different branch.
  • git merge <branch>: Merge changes from the specified branch into the current branch.
  • git log: View the commit history of the repository.
  • git remote -v: List remote repositories associated with your local repository.
  • git fetch: Download changes from the remote repository without merging them.
  • git reset <file>: Unstage a file that has been added to the staging area.
  • git rm <file>: Remove a file from the repository and stage the removal for commit.
  • git stash: Temporarily save changes that are not ready to be committed, allowing you to switch branches or pull changes without losing your work.
  • git tag <tag-name>: Create a tag for a specific commit, often used for releases.

Basic GitHub Workflow

  1. Create a Repository: Start by creating a new repository on GitHub.
  2. Clone the Repository: Use git clone <repository-url> to create a local copy of the repository.
  3. Make Changes: Edit files in your local repository as needed.
  4. Stage Changes: Use git add <file> to stage the changes you want to commit.
  5. Commit Changes: Use git commit -m "commit message" to commit your staged changes with a descriptive message.
  6. Push Changes: Use git push to upload your local commits to the remote repository on GitHub.
  7. Create a Branch: If you're working on a new feature or bug fix, create a new branch using git checkout -b <branch-name>.
  8. Make Changes in the Branch: Edit files and commit changes in your new branch.
  9. Push the Branch: Use git push origin <branch-name> to push your branch to GitHub.
  10. Create a Pull Request: Go to the GitHub repository page and create a pull request to merge your changes into the main branch.
  11. Review and Merge: Collaborators can review your pull request, suggest changes, or approve it. Once approved, you can merge the pull request into the main branch.
  12. Delete the Branch: After merging, you can delete the branch both locally and on GitHub to keep the repository clean.