Skip to content

Git Cheatsheet

Nikoleta Glynatsi edited this page Aug 11, 2024 · 1 revision

Setup

To retrieve an entire repository from a hosted location via URL:

$ git clone [url]

Status and History

To show modified files in working directory, staged for your next commit:

$ git status

To show all commits in the current branch’s history:

$ git log

Staging and Committing

To add a file as it looks now to your next commit (stage):

$ git add [file]

or to add all:

$ git add .

To diff of what is changed but not staged:

$ git diff

To diff of what is staged but not yet committed:

$ git diff --staged

To commit your staged content as a new commit snapshot:

$ git commit -m “[descriptive message]”

or to open nano to write you commit message just simply:

$ git commit

Branches

To list your branches. a * will appear next to the currently active branch:

$ git branch

To create a new branch:

$ git branch [branch-name]

To switch to another branch and check it out into your working directory:

$ git checkout [branch-name]

To retrieve and push updates

To fetch and merge any commits from the tracking remote branch:

$ git pull [remote-name] [branch-name]

To push local branch commits to the remote repository branch:

$ git push [remote-name] [branch-name]
Clone this wiki locally