Git Command Line
Posted on May 6, 2024 (Last modified on October 11, 2024) • 3 min read • 464 wordsVideo is in Swedish
Git is an essential tool for software developers, allowing them to track changes and collaborate on projects with ease. While there are many graphical user interfaces (GUIs) available for Git, the command line remains a powerful and efficient way to interact with the version control system. In this article, we’ll explore the basics of Git command line and provide you with a comprehensive guide to get you started.
Before diving into advanced topics, let’s cover some basic Git commands:
git init
: Initializes a new Git repository in your current directory.git add <file>
: Stages a file for the next commit.git add .
: Stages all changes in the current directory and its subdirectories.git commit -m "commit message"
: Commits staged changes with a specified commit message.git log
: Displays a list of all commits made to the repository, including commit messages and authors.git status
: Shows the status of your local repository, including any uncommitted changes.Git’s branching and merging capabilities allow you to work on multiple features or bug fixes simultaneously without affecting the main codebase. Here are some essential commands:
git branch <branch_name>
: Creates a new branch with the specified name.git checkout <branch_name>
: Switches your current branch to the specified one.git merge <branch_name>
: Merges changes from another branch into your current branch.To collaborate with others or share your project, you’ll need to interact with remote repositories. Here are some key commands:
git remote add origin <repository_url>
: Adds a remote repository with the specified URL.git push -u origin master
: Pushes local changes to the remote repository and sets the upstream tracking information.git pull origin master
: Fetches changes from the remote repository and merges them into your current branch.Once you’re comfortable with basic Git commands, it’s time to explore some advanced topics:
git reset --hard HEAD
: Resets your local repository to the last committed state.git stash
: Saves uncommitted changes temporarily, allowing you to switch branches or commit other changes.git cherry-pick <commit_hash>
: Applies a specific commit from another branch to your current branch.Mastering Git command line requires practice and patience, but it’s an essential skill for any software developer. By understanding the basic commands, branching and merging, remote repositories, and advanced topics, you’ll be able to efficiently manage your projects and collaborate with others. Remember to always use git status
and git log
to keep track of changes and commit messages.
For more information on Git command line, check out the official Git documentation or online tutorials like GitHub’s Git Tutorial. With practice and persistence, you’ll become a Git master in no time!
Swedish