Shows the current status of the working directory and staging area:
git status
Stages all changes in the current directory and its subdirectories:
git add .
Commits the staged changes with a message:
git commit -m "your comment"
Discards any changes in the working directory and resets to the last committed state:
git checkout -- .
Displays the commit history, and shows each commit summary in a single line:
git log --pretty=oneline
View Logs with Graphical Representation:
git log --graph --oneline --all
Hard reset: commits, staging area, and working directory are reverted.
git reset --hard HEAD^
Soft reset: only commits are reverted while staged and working changes stay.
git reset --soft HEAD^
Check the detailed difference:
git diff
List all branches and highlight the current branch:
git branch
Switch to a Branch:
git checkout <branch-name>
Create and Switch to a New Branch:
git checkout -b <new-branch-name>
Rename master to main:
git branch -m master main
Rename a Remote Repository:
git remote rename origin new-origin
Reset the current branch to match the state of the local feature branch exactly:
git reset --hard feature
Reset the current branch to match the state of the remote new-feature branch exactly:
git reset --hard origin/new-feature
Merge Feature Branch into main:
git merge feature-new-feature
Delete a Local Branch
git branch -d <branch-name>
Delete the Remote master Branch:
git push origin --delete master
Remove a Remote Repository:
git remote remove origin
Show Remote Repositories:
git remote -v
Add a Remote Repository:
git remote add origin <remote-url>
Download changes from the remote branch:
git fetch origin <branch-name>
Pull Latest Changes from Remote to Current Local Branch:
git pull origin <branch-name>
Push Local Branch to Remote:
git push origin <branch-name>
Push the main Branch to Remote(set default upstream branch as origin):
git push -u origin main
Clone the specified GitHub repository via SSH:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/private-key-repository
git clone git@github.com:xxx/yyy.git