Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
CONFIGURE USER INFORMATION FOR ALL LOCAL REPOSITORIES
| header 1 | header 2 |
|---|---|
| git config --global user.name "[name]" | Sets the name you want atached to your commit transactions |
| git config --global user.email "[email address]" | Sets the email you want atached to your commit transactions |
| git config --global color.ui auto | Enables helpful colorization of command line output |
START A NEW REPOSITORY OR OBTAIN ONE FROM AN EXISTING URL
| header 1 | header 2 |
|---|---|
| git init [project-name] | Creates a new local repository with the specified name |
| git clone [url] | Downloads a project and its entire version history |
Working with Local Branch
REVIEW EDITS AND CRAF A COMMIT TRANSACTION
| header 1 | header 2 |
|---|---|
| git log | See all commits |
| git log --no-merges [branch-name].. | See only changes made on particular branch |
| git log --pretty=format:"%h %s" --graph | Pretty commit view |
| git status -s | Lists all new or modified files to be commited |
| git status | Short view of status |
| git diff | Shows file differences not yet staged |
| git add [file] | Snapshots the file in preparation for versioning |
| git add . | Add all modified files to be commited |
| git add '*.txt' | Add only text files |
| git diff --staged | Shows file differences between staging and the last file version |
| git reset [file] | Unstages the file, but preserve its contents |
| git commit -m "[descriptive message]" | Records file snapshots permanently in version history |
NAME A SERIES OF COMMITS AND COMBINE COMPLETED EFFORTS (BRANCHING)
| header 1 | header 2 |
|---|---|
| git branch | Lists all local branches in the current repository |
| git branch [branch-name] | Creates a new branch |
| git checkout [branch-name] | Switches to the specified branch and updates the working directory |
| git checkout -b [new-branch-name] | Checkout current branch into a new branch |
| git merge [branch] | Combines the specified branch’s history into the current branch |
| git branch -d [branch-name] | Soft deletes the specified branch |
| git branch -D [branch-name] | Hard deletes the specified branch |
COMPARING CHANGES
| header 1 | header 2 |
|---|---|
| git diff | See current changes, that have not been staged yet. |
| git diff HEAD | See current changes, that have not been commited yet (including staged changes) |
| git diff branch-name | Compare current branch to some other branch |
| git diff [first-branch]...[second-branch] | Compare two different branches |
| git show [commit] | Outputs metadata and content changes of the specified commit |
ERASE MISTAKES AND CRAF REPLACEMENT HISTORY
| header 1 | header 2 |
|---|---|
| git reset [commit] | Undoes all commits afer [commit], preserving changes locally |
| git reset --hard [commit] | Discards all history and changes back to the specified commit |
SHELVE AND RESTORE INCOMPLETE CHANGES
| header 1 | header 2 |
|---|---|
| git stash | Temporarily stores all modified tracked files |
| git stash pop | Restores the most recently stashed files |
| git stash list | Lists all stashed changesets |
| git stash drop | Discards the most recently stashed changeset |
Working with Remote Branch
MANAGE REMOTE BRANCH
| header 1 | header 2 |
|---|---|
| git remote | See list of remote repos available. |
| git remote -v | Detailed view of remote repos, with their git urls |
| git remote add origin [https://some-git-remote-url] | Add a new remote. I.e. origin if it is not set |
SYNCHRONIZE CHANGES
| header 1 | header 2 |
|---|---|
| git push | Push current branch to remote branch |
| git push | [alias] [branch] Uploads all specific local branch commits to remote |
| git fetch | Downloads all history from the remote repository |
| git branch -a | See the list of all remote branches |
| git pull | Just like pushing, you can get the latest updates from remote. |
| git pull [alias] [branch] | Pull a specific branch |
Source: https://developerinsider.co/git-commands-cheat-sheet/
Add Comment
Please, Sign In to add comment