[ TechDocsCove ]  TechDocsCove en   ↩︎

# Demystifying Git: A Beginner's Guide to Version Control and Collaboration

git   source control  

translations: [ es/Español ] · [ fr/Français ] · [ de/Deutsch ]


Table of contents


Git is a powerful version control system used by developers to manage their projects efficiently. It offers a range of commands to track changes, collaborate, and maintain code. Let’s explore some fundamental and advanced Git commands.

Basic Commands

git init

Initialize a new Git repository in the current directory.

git init

The command creates a hidden directory named .git where Git stores its data for version control. This initializes a new, empty repository.

git clone

Clone an existing repository into a new directory.

git clone <repository_URL>

Cloning copies the entire repository from the specified URL to a new directory. It allows you to work on the code locally, keeping it synchronized with the remote repository.

git pull

Fetch changes from a remote repository and merge them into the local branch.

git pull origin main

This command updates your local branch with changes from the specified remote repository’s branch. It fetches the changes and merges them into your current working branch.

git push

Push local changes to a remote repository.

git push origin main

Using git push, you can send your committed changes from the local branch to the specified remote repository’s branch (main in this case). This keeps your changes synchronized across multiple locations.

Advanced Commands

git stash

Temporarily stash changes in the working directory.

git stash

This command saves the current modifications that are not ready to be committed into a “stash”. It’s useful when you want to switch branches or work on something else temporarily.

git stash pop

Apply the most recently stashed changes back into the working directory.

git stash pop

The pop command retrieves the most recent stashed changes and applies them back to the working directory, removing them from the stash. It’s essential after using git stash to reapply the changes.

git commit

Record changes to the repository with a commit message.

Inline Commit

git commit -m "Your commit message"

The -m flag allows you to add a commit message inline with the commit command. It’s suitable for small, straightforward changes where the message is brief.

Commit with Editor

git commit

This command opens your default editor, allowing you to enter a more detailed commit message. It’s beneficial for providing a comprehensive description of your changes.

Update Existing Commit Message

git commit --amend

The --amend option lets you edit the last commit message. It opens the default editor with the previous commit message, allowing you to modify it before finalizing the commit.



Created on: Jan 9, 2024


Email shareIcon for sharing via email    Reddit shareIcon for sharing via Reddit    X shareIcon for sharing via X    Telegram shareIcon for sharing via Telegram    WhatsApp shareIcon for sharing via WhatsApp    Facebook shareIcon for sharing via Facebook    LinkedIn shareIcon for sharing via LinkedIn