🧑🏻💻
Dev Tools & Commands
—GIT HUB REPOSITORY PUSH STEP BY STEP
[Link] to your project folder:
cd path/to/your/project-folder
2. Initialize Git in your folder:
git init
3. Add all files to staging
git add .
4. Commit the files
git commit -m "Initial commit"
5. Add remote GitHub repository
git remote add origin [Link]
Dev Tools & Commands 1
✅ 6. Push your code to GitHub
This pushes your code to the main branch. If your branch is master , replace main
with master .
git push -u origin main
Optional: To check if the remote is set correctly:
git remote -v
—GIT HUB REPOSITORY Update
🔧 Steps:
1. Open your project folder in terminal
Navigate to the folder that contains the .git directory.
2. Check the current status
git status
3. Add changes to staging
git add .
or to add a specific file/folder:
git add foldername/filename
Dev Tools & Commands 2
4. Commit the changes
git commit -m "Added new xyz folder/file"
5. Push to GitHub
git push origin main
💡 Tip:
If you get the “diverged” or “fetch first” error again, run:
git pull origin main --allow-unrelated-histories
then re-commit and push.
.gitignore – Ignoring Files and Folders in Git
When we want Git to stop tracking certain files or folders (like sensitive
information like API keysl), we can use a .gitignore file.
Steps:
1. First, we create a .gitignore file (if it doesn't already exist):
touch .gitignore
2. Then, we open the .gitignore file and add the names of the files or folders we
want Git to ignore.
Example:
[Link] # to ignore a specific file
images/ # to ignore an entire folder
3. We can verify it by running:
Dev Tools & Commands 3
git status
This will show us which files are being tracked or ignored.
Viewing Commit Logs in Git
To view the full commit history:
git log
To view the commit history in a compact, one-line format:
git log --oneline
Setting Global Git Username and Email
To set our Git identity (used in all repositories on our system), we run:
git config --global [Link] "anjandas" # our GitHub username
git config --global [Link] "anjanda1920@[Link]" # our GitHub email
Git Branches
Dev Tools & Commands 4
1. View current branch
git branch
Shows all local branches.
marks the branch you are on.
2. Rename current branch (e.g. master → main)
git branch -M main
M = move/rename (force if exists).
3. Create & switch to new branch
git checkout -b feature-login
Creates a new branch feature-login from current branch.
Dev Tools & Commands 5
Switches into it immediately.
(modern git also supports git switch -c feature-login )
4. Switch between branches
git checkout main
Moves back to main (or any branch).
5. Delete a branch (after merging)
git branch -d feature-login
Deletes local branch if already merged.
Force delete (if not merged):
git branch -D feature-login
6. Push branch to GitHub
git push -u origin feature-login
Pushes new branch to remote repo.
u links local → remote (so later you just do git push ).
7. Delete remote branch (if needed)
git push origin --delete feature-login
Dev Tools & Commands 6
🔹(GitHub)
Collaborative Development Flow
1. Admin (Repo Owner) creates project
# Create repo on GitHub called project1
git clone [Link]
cd project1
# Make an initial commit so repo is not empty
echo "# Project1" > [Link]
git add [Link]
git commit -m "Initial commit"
git push origin main
Now project1 exists on GitHub.
Admin goes to Settings → Collaborators → adds teammate.
2. Teammate gets repo
If collaborator:
git clone [Link]
cd project1
If not collaborator (open-source style):
Teammate clicks Fork on GitHub → their copy is created.
Then clone their fork:
git clone [Link]
cd project1
Dev Tools & Commands 7
3. Teammate creates a new branch
# Make sure on main
git checkout main
git pull origin main
# Create feature branch
git checkout -b feature-ui
4. Teammate does work
# Example: add a file
echo "<h1>Hello 🙋♂️
</h1>" > [Link]
git add [Link]
git commit -m "Added homepage"
5. Teammate pushes branch
git push -u origin feature-ui
6. Create Pull Request (PR)
GitHub automatically shows “Compare & pull request”.
Teammate clicks → writes PR → submits.
7. Admin reviews & merges
On GitHub (admin):
Open PR → review code → click Merge pull request.
Confirm merge → branch is merged into main.
Dev Tools & Commands 8
8. Everyone updates their local main
Admin & teammate run:
git checkout main
git pull origin main
Now both have the latest merged code.
🔹[Link]
Undo when changes are added but
(You ran git add [Link] but haven’t commit yet)
Unstage file (remove from staging, keep changes in working directory):
git reset [Link]
Unstage all files:
git reset
Discard changes completely (go back to last commit):
git checkout -- [Link]
(or in modern git: git restore [Link] )
🔹[Link] when changes are committed
pushed
(You ran git commit -m "msg" but not push )
Dev Tools & Commands 9
Change last commit message / add files into last commit:
git commit --amend
Undo last commit but keep changes staged:
git reset --soft HEAD~1
Undo last commit but keep changes unstaged:
git reset --mixed HEAD~1
Undo last commit and discard changes (⚠ irreversible):
git reset --hard HEAD~1
Undo when changes are pushed & merged into main
[Link] GitHub GUI :
1. Go to your repo on GitHub.
2. Click on the "Pull Requests" tab.
3. Find the merged PR (your teammate’s).
4. Open it → on the bottom, GitHub shows a "Revert" button.
Clicking it creates a new PR that undoes everything from that PR.
Merge that PR → and your main is back to before teammate’s merge.
2. Using Git (Admin repo locally)
Step 1: Make sure you’re up to date
Dev Tools & Commands 10
git checkout main
git pull origin main
Step 2: See commit history
git log --oneline
Find the commit hash just before the merge. (Let’s say it’s abc123 )
Step 3A: Safe rollback (recommended, keeps history)
git revert -m 1 <merge_commit_hash>
git push origin main
This makes a new commit that undoes the merge.
Step 3B: Hard reset (dangerous, rewrites history)
git reset --hard abc123
git push origin main --force
This completely removes the teammate’s merge from history.
⚠️ Only use if you’re sure no one else pulled the bad changes.
Dev Tools & Commands 11