Welcome to the ChaiCode Cohort! This documentation is designed to introduce you to Git
and GitHub
, two essential tools for developers in our company. The purpose of this guide is to help you set up, understand, and use these tools effectively for seamless collaboration and code management. Together, we’ll ensure smooth workflows and strong teamwork. 🚀
Git is a distributed version control system that allows developers to:
- Track changes in their code.
- Collaborate with teammates.
- Maintain a complete history of the project.
It ensures every change is documented and reversible, making it indispensable for modern software development.
- Version Control: Maintain a history of changes.
- Collaboration: Work with multiple team members on the same project without overwriting changes.
- Code Safety: Experiment with new features without affecting the main codebase.
GitHub is a cloud-based platform where you can store, share, and work together with others to write code:
- Centralized code repositories.
- Tools for code review, issue tracking, and continuous integration.
- Visit Git Downloads.
- Download the version suitable for your OS (Windows, macOS, Linux).
- Follow the installation instructions.
After installation, configure your name and email (must match your Chai Cohort email):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
To verify your configuration:
git config --list
Create an account on GitHub.
Generate an SSH key (if not already done): Follow prompts and save the key.
ssh-keygen -t rsa -b 4096 -C "your.email.com"
Copy the public key to GitHub: Go to GitHub Settings > SSH and GPG Keys > Add SSH Key and paste it.
cat ~/.ssh/id_rsa.pub
Authenticate GitHub via SSH Test the SSH connection:
ssh -T [email protected]
Copy the SSH/HTTPS URL and run:
git clone [email protected]:ravirajbhardwaj/Git-Github.git
cd Git-Github
Command | Usage |
---|---|
git init |
Initializes a new Git repository in your project folder. |
git clone <repository-url> |
Clones an existing repository from GitHub to your local machine. |
git status |
Displays the status of changes in your local repository. |
git add <file> |
Stages specific files for commit. |
git add . |
Stages all changes in the current directory for commit. |
git commit -m "message" |
Saves staged changes with a commit message. |
git branch |
Lists all branches in the repository. |
git branch <branch-name> |
Creates a new branch with the specified name. |
git checkout <branch-name> |
Switches to the specified branch. |
git merge <branch-name> |
Merges the specified branch into the current branch. |
git pull |
Fetches and merges changes from the remote repository into your branch. |
git push |
Pushes your commits to the remote repository. |
git remote add origin <url> |
Links your local repository to a remote repository on GitHub. |
git fetch |
Downloads changes from the remote repository without merging them. |
git log |
Shows a log of commits in the repository. |
git diff |
Displays changes not yet staged or committed. |
git reset <file> |
Unstages a file that was staged with git add . |
git rm <file> |
Removes a file from the working directory and the staging area. |
git push -u origin <branch-name> |
Pushes the branch and sets it to track the remote branch. |
git stash |
Temporarily stores changes not ready to be committed. |
git stash apply |
Reapplies the stored changes from the stash. |
git tag <tag-name> |
Creates a tag for the current commit (useful for versioning). |
git show <tag-name> |
Displays information about a specific tag. |
git rebase <branch-name> |
Moves or applies commits from one branch onto another. |
git cherry-pick <commit-hash> |
Applies a specific commit from one branch to another. |
git revert <commit-hash> |
Creates a new commit to undo the changes from a specific commit. |
- They provide a clear history of changes.
- Suggested Commit Message Guidelines:
- Help teammates understand the purpose of changes.
- Facilitate debugging and collaboration.
Rule | Description |
---|---|
Structure | Follow the format: <type>(<scope>): <description> |
Types | Use clear prefixes to describe the purpose of the commit: |
- feat |
A new feature. |
- fix |
A bug fix. |
- docs |
Documentation changes. |
- style |
Code style or formatting changes (no functional changes). |
- refactor |
Code refactoring without changing functionality. |
Examples | feat(auth): add user login functionality |
fix(api): resolve timeout issue in fetch requests |
|
Limit Subject to 50 Characters | Keep the subject concise and to the point. |
Use Present Tense | Write messages in the present tense, e.g., "Add feature" instead of "Added feature." |
Describe What and Why | Explain what changes were made and why they were necessary. |
-
Pull Requests (PRs)
- Keep PRs focused on a single feature or fix.
- Provide a detailed description of changes.
- Assign reviewers and address feedback promptly.
-
Branching Workflow
Main Branch
: Always deployable and stable.Feature Branches
: Develop new features or fixes (e.g., feature/login).Merge Strategy
: Merge feature branches into main via PRs.
- Commit often and meaningfully. Regularly pull updates to stay in sync.
- Resolve conflicts as soon as they arise.
By following this documentation, you'll quickly get up to speed with Git and GitHub, ensuring productive and collaborative development at ChaiCode. Let's build amazing things together!
Learn More in-Depth : Git and Github