-
To initialize a new Git repository
git init
-
Get the status of changes as untracked, modified, or staged in your working directory
git status
-
Used to stage all changes in the current directory and its subdirectories for the next commit
git add .
git add button.tsx input.tsx
-
Used to commit the changes that you have staged using
git add
to the Git repository. The-m
flag allows you to include a commit message directly from the command linegit commit -m "<message>"
-
Used to unstage changes that have been previously staged using
git add
git restore --staged <file>
git restore --staged button.tsx
-
Used to display a log of commits in a Git repository
git log
-
Used to reset the current branch to a specific commit or to unstage changes
git reset <hash-code>
-
Used to create a new branch in your Git repository named
branch-name
git branch <branch-name>
-
Used to switch your working directory to the branch named
branch-name
. This command is commonly used when you want to move to a different branch in your Git repositorygit checkout <branch-name>
-
Used to integrate changes from one branch, typically named
branch-name
into the currently checked-out branch. The branch you are merging into is often referred to as the "target" or "destination" branchgit merge <branch-name>
# Switch to the branch where you want to merge the changes git checkout main # Perform the merge with the feature branch git merge feature
This sequence of commands switches to the "main" branch (you can replace "main" with the name of your target branch) and then merges the changes from the "feature" branch into the "main" branch.
-
Used to display the URLs of the remote repositories associated with your local Git repository
git remote -v
-
Used to add a remote repository named
origin
to your local Git repositorygit remote add <url-name> "<url-value>"
git remote add origin "git@github.com:imopbuilder/git-cheat-sheet.git"
-
Used to change the URL of the remote repository named
origin
in your local Git configuration. This command is helpful when you need to update the remote URL, such as when the repository location has changedgit remote set-url <url-name> "<url-value>"
git remote set-url origin "git@github.com:imopbuilder/nextjs-express-turbo.git"
-
Used to push the changes from your local branch named
branch-name
to the remote repository namedurl-name
git push <url-name> <branch-name>
git push origin main
-
Used to pull the changes of the branch named
branch-name
from the remote repository namedurl-name
to the local Git repositorygit pull <url-name> <branch-name>
git pull origin main