name
What to do: Install Git and configure it to associate commits with your name and email.
- Install Git from git-scm.com.
- Configure your username and email:
git config --global user.name "Your Name" git config --global user.email "your-email@example. com"
- Verify configuration:
git config --list
- Create and initialize a directory as a Git repository:
mkdir MyProject cd MyProject git init - Purpose: Creates a .git folder to track changes.
- Create a file:
echo "Hello Git" > file1.txt- Stage and commit:
git add file1.txt
git commit -m "Initial commit: Added file1.txt"- Modify the file:
echo "Git is awesome!" >> file1.txt- Check status and differences:
git status
git diff- Unstage a staged file:
git reset file1.txt- Discard uncommitted changes:
git checkout -- file1.txt- Create a new branch:
git checkout -b feature-branch- List branches:
git branch- Rename a branch:
git branch -m feature-branch feature-enhanced- Merge a branch into the main branch:
git checkout main
git merge feature-enhanced- Resolve conflicts during merge:
git merge <branch-name>
git add <resolved-file>
git commit- Add a remote repository:
git remote add origin https://github.com/your-username/repo.git- Verify the remote:
git remote -v- Push changes:
git push -u origin main- Pull changes:
git pull origin main- Clone a remote repository:
git clone https://github.com/your-username/repo.git- Save uncommitted changes:
git stash- Apply stashed changes:
git stash apply- Drop the stash:
git stash drop- Tag the current commit:
git tag -a v1.0 -m "Version 1.0 release"- Push the tag:
git push origin v1.0- Use interactive rebase:
git rebase -i HEAD~3- Replace pick with edit or squash as needed.
- Apply a specific commit to another branch:
git cherry-pick <commit-hash>- Fork a repository and clone it locally:
git clone https://github.com/your-username/forked-repo.git- Create a branch, make changes, and push:
git checkout -b fix-typo
echo "Typo fixed" >> README.md
git add README.md
git commit -m "Fixed a typo"
git push origin fix-typo- Open a pull request on GitHub.
- Simulate conflicts by modifying the same file in two branches.
- Practice resolving conflicts with teammates.
- Create a .gitignore file:
echo "node_modules/" > .gitignore- Add and commit the .gitignore:
git add .gitignore
git commit -m "Added .gitignore"- Verify ignored files:
git status- Remove untracked files:
git clean -f- Create aliases:
git config --global alias.st status
git config --global alias.cm commit- Use the aliases:
git st
git cm -m "Message"======= name
feature-enhanced