Git - Github Notes
Git - Github Notes
What is Git?
Git Basics
● Initialize a repository:
git init
● Clone a repository:
git clone <repo_url>
● Check repository status:
git status
● Add files to staging area:
git add <file> or git add . (for all changes)
● Commit changes:
git commit -m "Commit message"
● View commit history:
git log
Undoing Changes
● Unstage a file:
git reset <file>
● Undo the last commit:
git reset --soft HEAD~1 (keep changes)
git reset --hard HEAD~1 (discard changes)
● Revert a commit:
git revert <commit_hash>
Git Workflow
.gitignore
● Used to ignore files/folders.
Example .gitignore:
plaintext
Copy code
node_modules/
.env
*.log
●
GitHub Basics
● What is GitHub?
○ A cloud-based platform for Git repositories.
○ Provides tools for collaboration, code review, and CI/CD.
● Key Features:
○ Pull Requests: Allow code reviews before merging.
○ Forks: Copy a repository to your account for modifications.
○ Issues: Track bugs, features, or tasks.
○ Actions: Automate workflows like testing and deployment.
GitHub Commands
● Fork a Repository:
○ Done on the GitHub interface.
○ Creates a copy of the repository in your account.
● Create a Pull Request (PR):
○ Propose changes from your branch to another branch or repository.
● Clone a Repository:
git clone <repo_url>
● Push to Forked Repository:
git remote add origin <forked_repo_url>
git push origin <branch_name>
Collaboration Workflow
1. Clone a repository:
git clone <repo_url>
2. Create a branch for your feature:
git checkout -b feature-branch
3.
4. Push changes to your branch:
git push origin feature-branch
5. Create a pull request on GitHub for review.
Best Practices