Skip to content

goku-kakarot1997/Git-Commands

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Git Commands Cheat Sheet

This README provides essential Git commands for working with GitHub using Git CMD (Command Prompt), along with brief explanations.


Setup & Config

Sets your global Git username (used for all repositories).

git config --global user.name "Your Name"

Sets your global email.

git config --global user.email "[email protected]"

Check local or global Git username.

git config user.name
git config --global user.name

List all config values (local or global).

git config --list
git config --global --list

Create / Clone Repos

git init

Initialize a new Git repository.

git clone https://github.com/username/repo.git

Clone an existing repository from GitHub.


Basic Workflow

git status

Check the status of your working directory and staging area.

git add filename
git add .

Stage file(s) or all files for commit.

git commit -m "Your commit message"

Commit staged changes.

git push origin branch_name

Push commits to GitHub on specified branch.

git pull origin branch_name

Pull latest changes from GitHub.


Branching

git branch

List local branches.

git branch new_branch

Create a new branch.

git checkout new_branch

Switch to a branch.

git checkout -b new_branch

Create and switch to a new branch.

git merge branch_name

Merge specified branch into current branch.


Undo / Reset

git restore filename

Discard changes in working directory (Git 2.23+).

git reset HEAD filename

Unstage a file.

git reset --hard

Reset all files to last commit (warning: destructive).


Remove / Rename

git rm filename

Delete a file and stage the removal.

git mv oldname newname

Rename a file and stage the rename.


Logs

git log

Show commit history.

git log --oneline --graph --all

Compact graph of all commits.


Authentication

git push https://[email protected]/username/repo.git

Push with username (use PAT/token in place of password).


Change Global Username / Email

git config --global user.name "New Name"
git config --global user.email "[email protected]"

Update global Git identity.


Additional Useful Commands

git stash

Temporarily save changes without committing.

git stash pop

Apply stashed changes.

git remote -v

Show remote URLs.

git fetch

Download changes without merging.

git diff

See unstaged changes.

git show commit_id

Show details of a specific commit.


Tip: Use SSH or Personal Access Tokens (PAT) for GitHub authentication to avoid password issues.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published