Skip to content

Git Basics @ Coding:

Basic Git Commands listed with what they do.

Installation:

Windows or Mac:

  • You must install Git from the website to use Git and version control your projects. Click Here

GNU / Linux:

  • Run the command below:
sudo apt-get install git

Repository Management Commands:

  • git init [project name]: Initializes a new Git repository in the current directory.
  • git clone <project url>: Downloads an existing repository from a remote location (e.g., Gitlab) to your local machine.
  • git remote add: Adds a new remote repository to your local repository.

Branching and Merging:

  • git branch: Creates, lists, or deletes branches.
  • git checkout: Switches between branches or restores files to a specific commit.
  • git merge: Merges changes from one branch into another.

Staging and Committing:

  • git add [file]: Stages files or directories for the next commit.
  • git commit: Commits staged changes with a commit message.
  • git reset: Resets changes to a specific commit or uncommits changes.

Status and Logging:

  • git status: Displays the status of your repository, including staged and unstaged changes.
  • git log: Shows a chronological list of commits.
  • git diff [file]: Displays differences between commits or between the working directory and the staging area.

Remote Interactions:

  • git push: Sends local commits to a remote repository.
  • git pull: Fetches and merges changes from a remote repository into your local branch.
  • git fetch [remote]: Downloads changes from a remote repository without merging.

Other:

  • git config: Sets or retrieves configuration options, such as user name and email address.
  • git rm [file]: Removes files or directories from the working directory and staging area.
  • git stash: Temporarily saves changes and resets the working directory.