Useful Commands in GitHub - aakash14goplani/FullStack GitHub Wiki
Name | Usage | Example |
---|---|---|
git init |
This command creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. | git init |
git clone |
Clone a repository into a new directory | git clone |
git add |
Add file contents to the index |
git add . OR git add <file_name>
|
git revert |
The staged information (files added using git add ) for selected paths are reverted to that of the HEAD version |
git revert |
git status |
Show the working tree status. Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git | git status |
git log |
Show commit logs |
git log OR git log --pretty=oneline --graph --all
|
git commit |
Record changes to the repository. Stores the current contents of the index in a new commit along with a log message from the user describing the changes. |
git commit -m "message" OR git commit -am "message"
|
git pull |
Incorporates changes from a remote repository into the current branch | git pull origin master |
git push |
Updates remote refs using local refs, while sending objects necessary to complete the given refs. | git push origin master |
git hash-object |
Computes the object ID value for an object with specified type with the contents of the named file (which can be outside of the work tree), and optionally writes the resulting object into the object database. | echo "text message" or symbol git hash-object --stdin |
git cat-file |
In its first form, the command provides the content or the type of an object in the repository |
git cat-file SHA1_key -t OR git cat-file SHA1_key -s OR git cat-file SHA1_key -p
|
git count-objects |
This counts the number of unpacked object files and disk space consumed by them, to help you decide when it is a good time to repack | git count-objects |
git tag |
Git has the ability to tag specific points in history as being important. Typically people use this functionality to mark release points (v1.0, and so on) |
annoted Tag => git tag -a mytag -m "myTag" Non-annoted tag / lightweight tag => git tag mytag
|
git branch |
List, create, or delete branches. |
git branch branch_name List Branch git branch Delete Branch git branch -d branch_name Create Branch git branch branch_name List all Branch git branch -
|
git checkout |
Switch branches or restore working tree files. Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch. |
git checkout branch_name |
git merge |
Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another. |
git merge branch_name |
git rebase |
Reapply commits on top of another base tip. If is specified, git rebase will perform an automatic git checkout before doing anything else. Otherwise it remains on the current branch. |
git rebase branch_name OR git rebase -i branch_name
|
git show |
Shows one or more objects (blobs, trees, tags and commits) |
List references in a local repository:git show-ref branch_name , other examples: git show commit_hash , git show HEAD , git show HEAD^ , git show HEAD^^ , git show HEAD~2 , git show HEAD~2^2
|
git diff |
Git diff gives you the differences between two areas. If I use diff without any argument, then it's going to compare the working area with the index. If I want to compare the stuff I want to commit with the stuff I already committed i.e. I want to compare the index with the repository. For that, you can use git diff --cached option |
git diff |
git rm |
Removes the file from Index area and restricts it to Working area when used with --cached option. It permanently removes file from index as well as working area when used with -f option |
git rm --cached OR git rm -f
|
git mv |
Moves/Rename files. Works like move
|
git mv abc.txt abc.md |
git reset |
First, it moves the current branch, so it also changes the current commit, and second, optionally, it copies the files and directories from the new current commit to the working area and the index. * the git reset --soft option means don't touch any of the areas. Just move the branch and skip step two entirely * the git reset --mixed option, reset copies data from the new current commit to the index, but leaves the working area alone. This is the default option, so if you don't give any option to reset, that will be a mixed reset * the git reset --hard option, then reset copies data from the new current commit to both the working area and the index. |
git reset |
git stash |
The stash is like a clipboard for your project. It's the place where you store stuff that you need to set aside for some time and it's a multiple clipboard that you can have as elements as you want. Each element gets labeled with information about the latest commit to make it easier to identify and it also gets a serial ID e.g. stash@{0}, the next one would be stash@{1} |
git stash save . important options: git stash --include-untracked , git stash list , git stash list , git stash clear
|
git blame |
Show what revision and author last modified each line of a file | git blame file_name |
git reflog |
Manage reflog information | git reflog HEAD |
Windows Commands
Name | Usage | Example |
---|---|---|
start |
This command opens windows explorer/file. | start folder/file_name |
cat |
This command reads content of a file. | cat file_name |
ls |
This command list the contents within directory. | ls |
tree |
This command prints the tree structure of directory. |
tree> tree.txt /a /f OR tree /f
|
move |
Rename a file (in e.g. a txt file to md file) | move abc.txt abc.md |