GitHub Beginner Commands From Scratch

 

Git Version

git --version

Push or Clone


Git will ask credentials

git push origin main

OR

git clone https://github.com/rohitgupta13130/AndriodIonicBackendHosted.git
cd AndriodIonicBackendHosted

When prompted:

Username: your-github-username
Password: PASTE_YOUR_PERSONAL_ACCESS_TOKEN

Done — Git is connected


Commands for a NEW Git Repository


Initializes a new Git repository in your project folder (creates .git).

git init

Shows current file status (untracked, modified, staged).

git status

Connects your local repo to a remote GitHub repository named origin.

git remote add origin https://github.com/shadabalamcse0/Node_API_Mysql.git

Stages all files for commit.

git add .

Saves a snapshot of staged files with a message.

git commit -m "Initial commit"

Renames the default branch to main (GitHub standard).

git branch -M main

Pushes code to GitHub
-u sets upstream so future git push works without arguments.

git push -u origin main


Change Remote Repository (if needed)


Removes the existing remote URL.

git remote remove origin

Adds a new GitHub repository as remote.

git remote add origin https://github.com/rohitgupta13130/AndriodIonicBackendHosted.git


Commands for an EXISTING Git Repository


Switches to the master branch (older default branch).
If your repo uses main, replace master with main.

git checkout master

Fetches latest changes from GitHub
-p removes deleted remote branches locally.

git fetch -p origin

Merges latest GitHub changes into your local master.

git merge origin/master

Switches to your working branch .

git checkout <feature-branch>

Updates your feature branch with latest master changes.

git merge master

Pushes updated feature branch to GitHub.

git push origin <feature-branch>


If You changed laptop / new system


git clone https://github.com/rohitgupta13130/AndriodIonicBackendHosted.git
cd AndriodIonicBackendHosted

No comments:

Post a Comment