DEV Community

shun
shun

Posted on • Updated on

Getting Started with Git Essential Commands

Configure Tooling

Sets the name you want attached to your commit transactions

git config --global user.name "[name]" 
Enter fullscreen mode Exit fullscreen mode

Sets the email you want attached to your commit transactions

git config --global user.email "[email address]" 
Enter fullscreen mode Exit fullscreen mode

Create Repositories

Creates a new local repository with the specified name

git init [project-name]
Enter fullscreen mode Exit fullscreen mode

Downloads a project and its entire version history

git clone [url]
Enter fullscreen mode Exit fullscreen mode

Make Changes

Lists all new or modified files to be committed

git status
Enter fullscreen mode Exit fullscreen mode

Shows file differences not yet staged

git diff
Enter fullscreen mode Exit fullscreen mode

Snapshots the file in preparation for versioning

git add [file]
Enter fullscreen mode Exit fullscreen mode

Records file snapshots permanently in version history

git commit -m "[descriptive message]"
Enter fullscreen mode Exit fullscreen mode

Group Changes

Lists all local branches in the current repository

git branch
Enter fullscreen mode Exit fullscreen mode

Creates a new branch

git branch [branch-name]
Enter fullscreen mode Exit fullscreen mode

Switches to the specified branch and updates the working directory

git checkout [branch-name]
Enter fullscreen mode Exit fullscreen mode

Combines the specified branch’s history into the current branch

git merge [branch]
Enter fullscreen mode Exit fullscreen mode

Deletes the specified branch

git branch -d [branch-name]
Enter fullscreen mode Exit fullscreen mode

Refactor Filenames

Deletes the file from the working directory and stages the deletion

git rm [file]
Enter fullscreen mode Exit fullscreen mode

Changes the file name and prepares it for commit

git mv [file-original] [file-renamed]
Enter fullscreen mode Exit fullscreen mode

Suppress Tracking

Lists the files and directories that git should ignore

.gitignore
Enter fullscreen mode Exit fullscreen mode

Review History

Displays commit history

git log
Enter fullscreen mode Exit fullscreen mode

Shows content differences between two branches

git diff [first-branch]...[second-branch]
Enter fullscreen mode Exit fullscreen mode

Save Fragments

Temporarily stores all modified tracked files

git stash
Enter fullscreen mode Exit fullscreen mode

Restores the most recently stashed files

git stash pop
Enter fullscreen mode Exit fullscreen mode

Lists all stashed changesets

git stash list
Enter fullscreen mode Exit fullscreen mode

Discards the most recently stashed changeset

git stash drop
Enter fullscreen mode Exit fullscreen mode

Synchronize Changes

Downloads all history from the repository bookmark

git fetch [bookmark]
Enter fullscreen mode Exit fullscreen mode

Combines bookmark’s branch into current local branch

git merge [bookmark]/[branch]
Enter fullscreen mode Exit fullscreen mode

Uploads all local branch commits to gitHub

git push [alias] [branch]
Enter fullscreen mode Exit fullscreen mode

Downloads bookmark history and incorporates changes

git pull
Enter fullscreen mode Exit fullscreen mode

Top comments (0)