| git init |
Initialization the git repository. |
| git config --global $user_name |
Set username for git globaly. |
| git config --global $user_email |
Set useremail for git globally. |
| git remote add origin $url |
Set git account. |
| git remote set-url origin $url |
Set remote url. |
Git Repository Commands |
| git checkout -b $new_branch_name |
Create new branch in stage. |
| git checkout $branch_name |
Change branch. |
| git branch -d $branch_name |
Delete branch in local stage. |
| git add $file_name |
Add new file to stage. |
| git add . |
Add all files to stage. |
| git status |
Displays the state of the working directory and the staging area. |
| git commit -m "$commits" |
Add files changes. |
| git reset --soft |
Remove commits only. |
| git reset --hard |
Used to reset the current branch to a previous commit. |
| git log -$numbers |
Used to shaw past commits. |
Remotes Interaction Commands |
| git push origin $branch_name |
Push code to another branch. |
| git push origin $branch_name -f |
Push code force fully and past all code remove. |
| git pull origin $branch_name |
Take pull code from another branch. |
| git merge $branch_name |
Merge from another branch. |
| git diff $branch1..branch2 |
Check file changes in master(red). |
| git diff-tree --no-commit-id --name-only -r $commit |
File changes in a commit. |
| git diff --name-only $branch1..branch2 |
Get only file names doff between two branches. |
| git cherry pick $commithash |
That will pull just the commit into your current branch. |
| git checkout $commit/$branch $full_file_path |
Reset the file to its previous state or branch state. |
| git remote set-url origin $url |
Set the remote url. |
| git clean -n , git clean -fx |
To remove ignored and non-ignored files. |
Git stash |
| git stash list |
To get the list of stash. |
| git stash apply $stash_name |
Applies the changes and leaves a copy in the stash. |
| git stash pop $stash_name |
Applies the changes and removes the files from the stash. |
| git stash clear |
To delete all changes in stash. |
| git diff [--options][--][..] |
Commit different between two commits for a single file. |
| git diff --staged |
Different stage. |
| git log --since='$date'--until='$date' |
Commits filter by date. |
| git diff mybranch..master --myfile.cs |
Different between two branches for single file. |
| git checkout -- $file1/to/restore |
Reset file to specific commit. |
| git show commmit$Id:path/to/file |
Show file changes for specific commit. |
| git reset HEAD -- $filename |
Remove file from staging. |