Git is a version control system that allows developers to track changes, collaborate with others, and manage different versions of code over time. It's widely used for software development to handle projects efficiently.
- Distributed: Every developer has a complete copy of the project’s history.
- Branching and Merging: Enables easy branching and merging, making it ideal for collaboration.
- Efficiency: Optimized for speed and efficient handling of large projects.
-
Initialize Repository
git init
- Creates a new Git repository. -
Staging Changes
git add <file>
- Stages changes for commit. -
Committing Changes
git commit -m "commit message"
- Commits staged changes with a descriptive message. -
Pushing to Remote Repository
git push origin <branch>
- Pushes changes to a branch on a remote repository (like GitHub). -
Pulling Updates
git pull origin <branch>
- Fetches and integrates changes from a remote repository.
git status
- Shows the status of your files in the working directory and staging area.git log
- Displays the commit history.git diff
- Shows the difference between the working directory and the staging area.git branch
- Lists branches; usegit branch <branch_name>
to create a new branch.git checkout <branch>
- Switches to the specified branch.
GitHub is a cloud-based platform for hosting Git repositories, enabling collaboration, version control, and open-source contributions. GitHub adds features like issue tracking, pull requests, and GitHub Actions (for CI/CD).
- Remote Repositories: Host and access code from anywhere.
- Collaboration: Share code, contribute via pull requests, and manage issues.
- GitHub Actions: Automate workflows such as CI/CD, testing, and deployments.
- Documentation: Use README files, wikis, and GitHub Pages for project documentation.
-
Clone a Repository
git clone <repo_url>
- Copies a remote repository to your local machine. -
Creating a New Repository on GitHub
- Go to GitHub and click "New" to create a repository.
- Set repository name, visibility (public/private), and initialize with a README if desired.
- Copy the URL to push your local project to GitHub.
-
Working with Pull Requests
- Fork the repository to create a copy under your account.
- Make changes, commit, and push them to your forked repository.
- Open a Pull Request from your fork to the original repository to request merging changes.
-
Creating Issues
- Go to the "Issues" tab in a repository.
- Describe the bug, feature, or task to manage collaboration and tracking.
- Repository: A project or folder containing your code and its history.
- Commit: A snapshot of changes made in the repository.
- Branch: A parallel version of the repository allowing independent development.
- Merge: Combines changes from one branch into another.
- Pull Request (PR): Proposes changes to be merged into another branch (often used in open-source projects).
- Fork: A copy of another repository under your account, often used to contribute to others’ projects.
- Clone: A local copy of a remote repository.
- Commit Often: Make frequent, meaningful commits with clear messages.
- Use Branches: Create branches for new features or bug fixes to keep the main branch clean.
- Write Good Commit Messages: Keep messages short but descriptive.
- Pull Before Push: Regularly pull changes from the main branch to avoid merge conflicts.
Use Git and GitHub together to streamline collaboration, code review, and version control in your projects!