Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bryandidur
Last active August 1, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryandidur/6e016d7d7e32dea2d9b8446ced6e7d97 to your computer and use it in GitHub Desktop.
Save bryandidur/6e016d7d7e32dea2d9b8446ced6e7d97 to your computer and use it in GitHub Desktop.
Git Basic Commands

1) Initialize a GIT repository

cd /path/to/your/project

git init

2) Add files to the 'staging area'

git add `filename.ext` // Add a single file

git add -A             // Add all 'working directory' and 'unstaged' files

3) Commit the files

git commit -m `commit_message``

4) Reset all changes in the 'working directory' and 'unstaged'

git stash -u

5) Show commits:

git log                  // Show all commits (default visualization)

git log -p               // Show all commits with all its data

git log --pretty=oneline // Single lines

git log --stat           // Show commit statistics

git log --since=`x`.days || git log --since=`x`.weeks // Show a time based list of commits

6) Move files from 'staging area' back to the 'working directory'

git reset HEAD `filename.ext`

7) Coming back versions

git checkout `commit_hash`        // Creates a new branch at the commit point

git checkout `commit_hash` --soft // Returns the project to the given commit, keeping the 'untracked' and 'working directory' files untouched

git checkout `commit_hash` --hard // Returns the project to the given commit, but in the commit state. (with files already commited)

8) Working with branchs

git branch                    // Show all branchs

git branch `branch_name`      // Creates a new branch from the current branch

git checkout -b `branch_name` // Creates a new branch and checkout to it

git checkout `branch_name`    // Checkout to the branch

git merge `branch_name`       // Merges the `branch_name` commits to the current branch

git rebase `branch_name`      // Rebase (merge and organize) commits from the `branch_name` to the current branch (Prefer to use only locally)

git branch -d `branch_name`   // Deletes a branch

9) Using GIT blame

git blame `file`                             // Show the author of all the file lines

git blame `file` -L `from_line`,`up_to_line` // Show the specified lines author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment