Daily Used Git Commands
Basic Commands
-
Initialize a new Git repository:
git init
-
Check the status of your repository:
git status
-
Add files to the staging area:
git add <file> git add .
-
Commit changes with a message:
git commit -m "Your commit message"
-
View commit history:
git log git log --oneline
Branching and Merging
-
List all branches:
git branch
-
Create a new branch:
git branch <branch-name>
-
Switch to a branch:
git checkout <branch-name>
-
Create a new branch and switch to it:
git checkout -b <branch-name>
-
Merge a branch into the current branch:
git merge <branch-name>
-
Rebase the current branch onto another branch:
git rebase <branch-name>
Undoing Changes
-
Discard changes in the working directory:
git restore <file>
-
Unstage changes from the staging area:
git restore --staged <file>
-
Revert a commit by creating a new commit:
git revert <commit-hash>
Remote Repositories
-
Clone a remote repository:
git clone <repository-url>
-
Add a remote repository:
git remote add <remote-name> <repository-url>
-
Fetch changes from a remote repository:
git fetch <remote-name>
-
Pull changes from a remote repository:
git pull <remote-name> <branch-name>
-
Push changes to a remote repository:
git push <remote-name> <branch-name>
Reference
https://lokalise.com/blog/10-git-commands-for-day-to-day-work/
https://gist.github.com/dbarowy/dd84c4f9f5314da7ab7ddad73f51ba4f
https://git-scm.com/docs/everyday
https://www.loginradius.com/blog/engineering/git-commands/