![]() |
Git is a powerful version control system that is important for managing source code in modern software development. While there are many graphical user interfaces (GUIs) available for Git, mastering Git shell commands can significantly enhance your productivity and control over your repositories. This article provides an overview of essential Git shell commands and how to use them effectively. Steps to Use Git Shell CommandsBelow is the general workflow when using Git Bash: Step 1: Open Git BashLaunch the Git Bash application on the system. Step 2: Navigate to the Project DirectoryUse the cd command to change the current working directory to the location of the project. cd path/to/your/project
For Example ![]() Navigate to the Project Directory Initialize a Git RepositoryIf it isn’t done already, run git init to create a new Git repository in the project directory. git init
Output ![]() Initialize a Git Repository Add Files to the Staging AreaUse git add <file_name> to add specific files, or git add . to add all changes in the current directory to the staging area. git add <file_name> Output ![]() Add Files to the Staging Area Commit ChangesRun git commit -m “commit message” to save the staged changes with a descriptive commit message. git commit -m "commit message"
Output ![]() Commit Changes View Commit HistoryUse git log to see a list of past commits with their associated messages and details. git log
Output ![]() View Commit History Create BranchesExecute git branch <branch_name> to create a new branch. git branch <branch_name>
For Example: ![]() Create Branches Switch BranchesUse git checkout <branch_name> to switch to a different branch. git checkout <branch_name>
For Example ![]() Switch Branches Merge BranchesRun git merge <branch_name> to merge changes from one branch into another. git merge <branch_name>
For Example ![]() Merge Branches Push Changes to a Remote RepositoryIf we’re collaborating with others, use git push <remote_name> <branch_name> to upload our commits to a remote repository (e.g., on GitHub or GitLab). git push <remote_name> <branch_name>
For Example ![]() Push Changes to a Remote Repository Pull Changes from a Remote RepositoryRun git pull <remote_name> <branch_name> to download and integrate changes from the remote repository into the local branch. git pull <remote_name> <branch_name>
For Example ![]() Pull Changes from a Remote Repository Check the Current StateUse git status to check the current state of the repository and see which files have been modified or staged. git status
Output ![]() Check the Current State Explore other Git commands like git rebase, git stash, git reset, and git tag for more advanced operations. Note: To install Git Bash see this. ConclusionIn conclusion, git shell commands provide a powerful and flexible way to interact with the Git version control system. Using this, we can effectively manage our codebase, collaborate with others, and maintain a clear history of our project’s development. |
Reffered: https://www.geeksforgeeks.org
Git |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |