This README provides a comprehensive reference for common Git commands used in version control.
To check the installed version of Git, use:
git --versionTo initialize a new Git repository in your project directory, run:
git init-
To stage a specific file:
git add filename
-
To stage only the changed files:
git add . -
To stage all files in the current directory:
git add * -
To unstage a file:
git reset filename
To commit staged changes with a message, use:
git commit -m "Your commit message"To commit all changes in the current directory (including new files) with a message:
git commit -m "Your commit message"You can repeat the staging and committing process as needed:
git add . # (to stage changes again)
git commit -m "Second commit" # (note: fix any typos in your commit messages)-
To see the status of your files (staged, unstaged, untracked):
git status
-
To view the changes made in the working directory:
git diff
-
To view changes between the last commit and the working directory:
git diff --cached
-
To view the commit history:
git log
To push your changes to the remote repository:
git pushTo rename the current branch to main, use:
git branch -M mainTo create a new branch:
git branch new-branch-nameTo switch to a different branch:
git checkout branch-nameTo create and switch to a new branch in one command:
git checkout -b new-branch-nameTo merge a branch into the current branch:
git merge branch-nameTo add a remote repository, run:
git remote add origin <url>To push changes to the main branch on the remote repository:
git push -u origin mainTo fetch and merge changes from the remote repository:
git pull origin mainGit LFS is an extension for managing large files in Git repositories. To use Git LFS:
-
Install Git LFS (if not already installed):
git lfs install
-
Track large files (e.g., images, binaries):
git lfs track "*.psd" -
Add and commit changes as usual:
git add .gitattributes git add filename.psd git commit -m "Add large file" -
Push changes to the remote repository:
git push
| Command | Description |
|---|---|
git --version |
Check the installed version of Git |
git init |
Initialize a new Git repository |
git add filename |
Stage a specific file |
git add . |
Stage all changed files |
git add * |
Stage all files in the current directory |
git reset filename |
Unstage a specific file |
git commit -m "message" |
Commit staged changes with a message |
git commit -am "message" |
Commit all changes with a message |
git status |
Check the status of your files |
git diff |
View changes made in the working directory |
git diff --cached |
View changes between the last commit and staged changes |
git log |
View the commit history |
git push |
Push changes to the remote repository |
git branch -M main |
Rename the current branch to main |
git branch new-branch-name |
Create a new branch |
git checkout branch-name |
Switch to a different branch |
git checkout -b new-branch-name |
Create and switch to a new branch |
git merge branch-name |
Merge a branch into the current branch |
git remote add origin <url> |
Add a remote repository |
git push -u origin main |
Push changes to the main branch on remote |
git pull origin main |
Fetch and merge changes from the remote repository |
git lfs install |
Install Git LFS |
git lfs track "*.psd" |
Track large files with Git LFS |
Feel free to customize the commands and descriptions as per your requirements!