Git Commands Cheat Sheet
Command | Description | Example |
---|---|---|
git init |
Initialize a new Git repository. | git init my-repo |
git clone |
Clone a repository into a new directory. | git clone https://github.com/user/repo.git |
git status |
Show the working tree status. | git status |
git add |
Add file contents to the index (staging area). | git add filename.txt |
git commit |
Record changes to the repository. | git commit -m "Commit message" |
git push |
Update remote refs along with associated objects. | git push origin main |
git pull |
Fetch from and integrate with another repository or a local branch. | git pull origin main |
git branch |
List, create, or delete branches. | git branch new-branch |
git checkout |
Switch branches or restore working tree files. | git checkout new-branch |
git merge |
Join two or more development histories together. | git merge branch-name |
git log |
Show the commit logs. | git log |
Git Commands User Journey
=========================
Step 1: Initialize Repository
Command: git init
Description: Create a new Git repository in the current directory.
Example:
git init my-repo
Step 2: Clone an Existing Repository
Command: git clone
Description: Make a copy of an existing repository from a remote server.
Example:
git clone https://github.com/user/repo.git
Step 3: Check Repository Status
Command: git status
Description: View the current status of your working directory and staging area.
Example:
git status
Step 4: Stage Changes
Command: git add
Description: Stage changes for the next commit.
Example:
git add filename.txt
Step 5: Commit Changes
Command: git commit
Description: Record the staged changes in the repository.
Example:
git commit -m "Commit message"
Step 6: Push Changes to Remote
Command: git push
Description: Upload your local commits to a remote repository.
Example:
git push origin main
Step 7: Pull Updates from Remote
Command: git pull
Description: Fetch and integrate changes from the remote repository into your current branch.
Example:
git pull origin main
Step 8: Branching
Command: git branch
Description: Create, list, or delete branches for different features or fixes.
Example:
git branch new-branch
Step 9: Switching Branches
Command: git checkout
Description: Switch between branches in your repository.
Example:
git checkout new-branch
Step 10: Merging Changes
Command: git merge
Description: Combine changes from one branch into another.
Example:
git merge branch-name
Step 11: View Commit History
Command: git log
Description: Display the commit history for the repository.
Example:
git log
Conclusion
This Git commands user journey outlines the typical steps a developer goes through when managing a project with Git. By following this timeline, you can effectively initialize a repository, make changes, and collaborate with others. Happy coding!
Top comments (0)