Skip to content
/ git Public

Beginners guide that helps with git commands.

Notifications You must be signed in to change notification settings

jesuspinar/git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Git Introduction

A beginner's guide to essential Git commands and configurations.

This guide provides a collection of common Git commands, along with explanations on how to configure and use Git for version control. Whether you're just getting started or need a reference for frequently used commands, this guide is designed to help.


Table of Contents

  1. Global Configuration
  2. Useful Git Commands

Global Configuration

Set your name

To configure Git to use your name in commits, run:

git config --global user.name "Your name"

Set your email

To set the email associated with your Git commits:

git config --global user.email "[email protected]"

Set default text editor

If you want to set a default text editor, such as VSCode, for commit messages:

git config --global core.editor "code --wait"

Open Git config settings

To open and edit Git’s global configuration settings:

git config --global -e

Set line ending preferences

For Linux/Mac systems (use Unix-style line endings):

git config --global core.autocrlf input

For Windows systems (use Windows-style line endings):

git config --global core.autocrlf true

For other options, you can view the Git configuration help:

git config -h

Useful Git Commands

Initialize a Git repository

To initialize a new Git repository in the current folder:

git init

Stage changes

To stage all changes (deleted, modified, and new files):

git add .

Make a commit

To create a new commit with a message:

git commit -m "Initial commit"

Remove files

To remove a file from your working tree and stage the removal:

git rm <file>

Rename or move files

To rename or move a file:

git mv <old-filename> <new-filename>

View status

To check the status of your working directory:

git status

For a more concise, cleaner output of the status:

git status -s

View differences

To view the unstaged differences in your working directory:

git diff

To compare the changes already staged for commit:

git diff --staged

View commit history

To view the commit history:

git log

For a simplified, one-line-per-commit view:

git log --oneline

Branch management

  • To view the current branch:

    git branch
  • To view all local and remote branches:

    git branch -vva
  • To create and switch to a new branch:

    git checkout -b <branch-name>
  • To delete a local branch:

    git branch -d <branch-name>
  • To switch between branches:

    git switch <branch-name>

Merging changes

To merge changes from one branch into your current branch:

git merge <branch-name>

Working with remotes

  • To add a remote repository:

    git remote add origin https://github.com/your/repo.git
  • To push changes to a remote branch:

    git push origin <branch-name>
  • If local and remote branch names are different:

    git push origin <local-branch>:<remote-branch>
  • To create and push to a main branch:

    git push -u origin main
  • To list, remove, or rename remote repositories:

    git remote -v
    git remote rm <name>
    git remote rename <oldname> <newname>
  • After pulling changes, to view the history of changes:

    git whatchanged

For more details and advanced options, refer to the Git documentation.

About

Beginners guide that helps with git commands.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published