Git commands :
1. Git configuration :
git config --global user.name "<Your-Full-Name>" // Sets your name for all Git repositories.
git config --global user.email "<your-email-address>" // Sets your email for all Git repositories.
2. Git repository management :
git init // Initializes a new Git repository in the current directory.
git clone <url> // Clones a repository from a remote URL.
3. File status and staging :
git status // Displays the status of the working directory and staging area.
git add . // Stages all changes (new files, modifications, and deletions) for commit.
git commit -m 'message' // Commits the staged changes with a descriptive message.
4. Pushing changes :
git push // Pushes local commits to the remote repository.
5. Branching and switching branches:
git branch <branch-name> // Creates a new branch locally.
git checkout <branch-name> // Switches to an existing branch.
git checkout -b <branch-name> // Creates and switches to a new branch.
git merge <branch-name> // Merges the specified branch into the current branch.
6. Fetching and pulling changes :
git pull // Fetches and merges changes from the remote repository to your local repository.
7. Commit history and differences :
git log // Displays the commit history of the repository.
git diff // Shows the differences between files or commits.
8. Resetting changes :
git reset // Resets changes to the last commit or a specific state (e.g., git reset HEAD <file> to unstage changes).
git reset --hard // Resets the working directory and staging area to the last commit (losing local changes).
9. git stash :
git stash // Saves all uncommitted changes (tracked files only). Resets your working directory to the last committed state.
No comments:
Post a Comment