0% found this document useful (0 votes)
7 views

Git - Github Notes

Git is a distributed version control system that allows developers to track changes and collaborate on code. Key features include repositories, branching, merging, and syncing with remote repositories, while GitHub enhances collaboration with tools like pull requests and issues. Best practices include writing meaningful commit messages, using branches for features, and regularly pulling updates to avoid conflicts.

Uploaded by

Somnath singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Git - Github Notes

Git is a distributed version control system that allows developers to track changes and collaborate on code. Key features include repositories, branching, merging, and syncing with remote repositories, while GitHub enhances collaboration with tools like pull requests and issues. Best practices include writing meaningful commit messages, using branches for features, and regularly pulling updates to avoid conflicts.

Uploaded by

Somnath singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Git - Github Notes

What is Git?

●​ Git is a distributed version control system.


●​ Tracks changes in code, allowing collaboration among developers.
●​ Works locally, unlike centralized systems like SVN.
●​ Main components:
○​ Repository: Stores code and version history.
○​ Working Directory: Current folder being worked on.
○​ Staging Area: Holds changes before committing.
○​ Commit: A snapshot of your changes.

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

Branching and Merging

●​ Create a new branch:​


git branch <branch_name>
●​ Switch to a branch:​
git checkout <branch_name>
●​ Create and switch branch:​
git checkout -b <branch_name>
●​ Merge branches:​
git merge <branch_name> (merge into current branch)
●​ Delete a branch:​
git branch -d <branch_name>

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>

Syncing with Remote

●​ Add a remote repository:​


git remote add origin <repo_url>
●​ Push changes to remote:​
git push origin <branch_name>
●​ Pull changes from remote:​
git pull origin <branch_name>
●​ Fetch changes without merging:​
git fetch origin

Git Workflow

1.​ Modify files in the working directory.


2.​ Stage changes using git add.
3.​ Commit changes using git commit.
4.​ Push changes to a remote repository using git push.

.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

Make changes and commit:​


bash​
Copy code​
git add .
git commit -m "Add feature"

3.​
4.​ Push changes to your branch:​
git push origin feature-branch
5.​ Create a pull request on GitHub for review.

GitHub Advanced Features

●​ GitHub Actions: Automate workflows (e.g., CI/CD pipelines).


●​ GitHub Pages: Host static websites directly from a repository.
●​ Webhooks: Trigger events in real-time (e.g., notify a server on a new PR).
●​ Security:
○​ Use branch protection rules.
○​ Set up required reviews for PRs.
○​ Store sensitive data in encrypted secrets.

Git Commands Cheat Sheet


Command Description

git init Initialize a new Git repository.

git clone <url> Clone a remote repository.

git status Check the state of your working directory.

git add <file> Stage a file for commit.

git commit -m "msg" Commit changes with a message.


git push origin Push changes to a remote repository.
<branch>

git pull origin Pull changes from a remote repository.


<branch>

git branch List all branches.

git checkout Switch to a specific branch.


<branch>

git merge <branch> Merge a branch into the current branch.

git reset Undo changes.

git log View commit history.

git stash Temporarily save uncommitted changes.

Best Practices

1.​ Write meaningful commit messages.


2.​ Use branches for features and bug fixes.
3.​ Regularly pull updates from the main branch to avoid conflicts.
4.​ Use .gitignore to exclude unnecessary files.
5.​ Protect your main branch with review requirements.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy