Skip to main content

Section 13.6 Git Commands

While some tools like GitHub Desktop offer a graphical interface, many developers use Git through the command line, a text-based way to interact with your computer. It might feel unfamiliar at first, but it gives you a lot of control and speed once you get the hang of it. To use Git this way, you’ll open a terminal (on macOS/Linux) or Git Bash (on Windows), then type commands to tell Git what to do, like checking the status of your files or pushing your changes to GitHub.
Below is a list of some of the most common Git commands you’ll use as you start working with version control:
  • Set up Git (only once per machine)
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
  • Clone a remote repository
    git clone https://github.com/user/repo.git
    
  • Check the status of your working directory
    git status
    
  • Check the status of your working directory
    git status
    
  • Stage a file to be committed
    git add filename
    
  • Commit your staged changes with a message
    git commit -m "Describe your changes"
    
  • Push your changes to the remote repository
    git push
    
  • Pull the latest changes from the remote
    git pull
    
  • Create and switch to a new branch
    git checkout -b feature-branch-name
    
  • Switch back to an existing branch (e.g., main)
    git checkout main
    
  • Merge another branch into your current one
    git merge feature-branch-name
    

Note 13.6.1.

💡 Tip: You don’t have to memorize everything! Start with a few commands and build up as you go.
Figure 13.6.2. Step-by-step workflow for writing, committing, and sharing code using GitHub and VS Code.

Subsection 13.6.1 Learning to Use Git Like a Pro

Git is a powerful tool for managing your work. While it’s most commonly used for tracking code, it’s not limited to that. Git can be used to version and manage all kinds of files, including Word documents, spreadsheets, and other types of content. It’s essentially a smart file management and backup system that helps you track changes over time, recover earlier versions, and collaborate with others more effectively.
Like any tool, Git works best when you understand how to use it properly. Just as you’d turn to a user manual to operate a piece of equipment or troubleshoot an issue, developers frequently consult Git documentation to understand commands, resolve errors, or learn new techniques.
You’re not expected to memorize everything. Instead, part of being an effective problem solver is knowing how to find and use the right resources when you need them. This habit isn’t just about using Git, its a core part of problem solving in general: identifying the challenge, exploring resources, and applying what you learn to find a solution.
To practice the basics follow this step by step how to git tutorial. For the complete documentation refer to the git official website and the Pro Git book.
You have attempted of activities on this page.