Git Hub Commands

Rajesh GurajalaRajesh Gurajala
2 min read

LOCAL REPO :

๐Ÿ“ฆ Basic Git & File Setup

git init

๐Ÿ“ฆ Staging & Committing Changes

git add .

Stages all changes in the current directory.

git status

Shows the current status of changes (staged, unstaged, untracked).

git restore --staged names.txt

Unstages names.txt if it was added using git add.


๐Ÿ“ฆ Commit History & Undo

git commit -m "message"

Commits all staged changes with a message.

git log

Shows the list of past commits.

git reset <commit_id>

Uncommits all commits after the specified commit.
Use the commit ID from git log.


๐Ÿ“ฆ Pushing Code

git push origin main

Pushes to remote named origin, branch main.


๐Ÿ“ฆ Stash Commands

git stash

Saves all staged and unstaged changes, and cleans working directory.
โœ… Keeps local changes safe without committing.

git stash pop

Applies the latest stashed changes back to working directory.

git stash clear

Deletes all stashed entries (irreversible).


REMOTE REPO :

git remote add origin url                # Naming your remote repo as origin with url
git remote -v                            # List all URLs saved

git branch                               # Show current branch
git branch feature                       # Create new branch called feature
git checkout feature                     # Shift to feature branch

WORKING WITH EXISTING PROJECTS :

i)

  1. Fork ur desired repo to ur account.

  2. git clone < forked_repo_url >

  3. Make ur changes and while working:

  4. Never push on main branch, create on newly created branch only.

  5. Every time u are going to push, create a new branch for every pr.

ii)

1) Just like removing commits above i-th commit with git reset id-of-commit, similarly u can remove prs by u above i-th pr by simply git reset id-of-commit, and then do git push origin raj -f where raj is branch u previously pushed those extra prs

[ useful while ur pushing many prs on a same branch in ur remote repo. ]

2) How to sync upstream repo and ur [ remote repo, local repo ] ??

git checkout main

git pull upstream main [ Now both upstream and local repos synced]

git push origin main [ Now ur remote repo also synced]

0
Subscribe to my newsletter

Read articles from Rajesh Gurajala directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rajesh Gurajala
Rajesh Gurajala