Git Bash on Windows typically includes several text editors, either as built-in options or through external installations. Below is a list of editors you can use with Git Bash and how to open them: 1. Nano (Default Editor) Description : A simple terminal-based text editor that's often the default in Git Bash. Command to Open : nano filename 2. Vim Description : A powerful and widely-used terminal-based editor. Command to Open : vim filename If vim is not installed by default, install it via a package manager like Chocolatey: choco install vim 3. Vi Description : The predecessor to Vim and a simpler terminal editor. Command to Open : vi filename Note : vi might redirect to vim in some systems. 4. Emacs Description : A versatile editor often used by developers. Command to Open : emacs filename Note : Emacs is not included by default in Git Bash but can be installed. 5. Notepad Description : The built-in Windows Notepad editor. Command to Open : notepad filename 6. Notepad++ Descri...
A Comprehensive Guide to Git Commands with Examples
Git is a powerful version control tool that lets you track changes, collaborate, and manage code efficiently. Here's a guide to essential Git commands, their uses, and cool examples.
Getting Started with Git using Git bash
1. git init
- Use: Initializes a new Git repository.
- Example: Starting a new project.
Output: Creates a
.git
directory to track changes.
2. git clone
- Use: Clones a remote repository to your local machine.
- Example: Cloning a GitHub repository.
Output: A local copy of the repository is created in
repo/
.
Working with Changes
3. git add
- Use: Stages changes for commit.
- Example: Adding all files in a project.
Output:
file.txt
is staged for the next commit.
4. git commit
- Use: Saves staged changes to the local repository.
- Example: Committing changes with a message.
Output: A commit is created with your changes.
5. git status
- Use: Shows the status of the working directory and staging area.
- Example: Checking for staged and unstaged changes.
Output: Lists changes to be committed and untracked files.
6. git diff
- Use: Displays differences between changes.
- Example: Viewing what changed in
file.txt
.Output: Highlights added lines in
file.txt
.
Managing Branches
7. git branch
- Use: Lists, creates, or deletes branches.
- Example: Creating a new branch.
Output: Lists all branches, marking the current one with
*
.
8. git checkout
/ git switch
- Use: Switches between branches.
- Example: Switching to
feature-1
.Output: You’re now on the
feature-1
branch.
9. git merge
- Use: Merges changes from one branch to another.
- Example: Merging
feature-1
intomain
.Output: Combines
feature-1
intomain
.
Collaborating with Others
10. git pull
- Use: Fetches and integrates changes from a remote repository.
- Example: Syncing the local branch with the remote
main
.Output: Updates your local branch with the latest changes.
11. git push
- Use: Uploads local commits to a remote repository.
- Example: Pushing
feature-1
to the remote repository.Output: Updates the remote
feature-1
branch.
Undoing Changes
12. git reset
- Use: Unstages changes or reverts the branch.
- Example: Unstaging a file.
Output:
file.txt
is no longer staged but remains changed.
13. git revert
- Use: Reverts a specific commit.
- Example: Undoing a commit while keeping history.
Output: Creates a new commit that reverses changes.
Inspecting History
14. git log
- Use: Shows commit history.
- Example: Viewing commit history in detail.
Output: Displays concise commit history.
15. git show
- Use: Displays details about a specific commit.
- Example: Inspecting a recent commit.
Output: Shows changes and metadata for the commit.
Advanced Commands
16. git stash
- Use: Temporarily saves uncommitted changes.
- Example: Stashing changes before switching branches.
Output: Changes are safely stored and reapplied.
17. git fetch
- Use: Fetches updates from a remote repository without merging.
- Example: Checking for new updates.
Output: Updates are downloaded but not applied.
Conclusion
These examples demonstrate Git commands in action. Practice using them in a real project to master version control!
Comments
Post a Comment