Git command to initialize any project:
$git init
Command to add changes:
$git add -A
or
$git add .
or
$git add filename.extension
Command to commit changes:
$git commit -m "Commit Message"
Command to create repository
$git create
Command to push changes:
$git push
or
$git push origin
or
$git push origin branch_name
command to push the changes forcefully:
$git push -f
Command to get the log of the repository:
$git log
or
$git log -n 1
or
$git log –-since=2017-01-21
or
$git log –-until=2017-01-22
or
git lg -p
or
$git log –-grep="Init"
Command to get help of command:
$git help command
Example::
$git help log
Git Command to check log of individual file
$git log -- [filename]
Use --follow option in git log to view a file's history
$git log --stat -p -- src/somefile.ts
Command to check to status of repository:
$git status
or
$git status -s
Command to check difference in the repository:
$git diff
or
$git diff filename
or
$git diff --staged
or
$git diff --cached
Command to delete filename:
$git rm filename
Command to delete filename from staged or cached index:
$git rm --cached
Command to rename filename:
$git mv filename newfilename
$git checkout -- <file>
-- indicates current branch
$git reset HEAD <file>
$git commit --amend -m “Previous comment message copy and paste here.”
$git checkout lastcommitchecksum -- <file>
-- means present directory
lastcommitchecksum means there will checksum every commit that needs to be placed here
$git revert lastcommitchecksum
It will pop-up in a file, then save and exit
Soft reset commit
$git reset --soft commitchecksum
Mixed reset commit
$git reset --mixed commitchecksum
Hard reset commit
$git reset --hard commitchecksum
$git clean
$git clean -n
$touch .gitignore
.gitignore
It is used to ignore files which you mention in .gitignore
$git config –global core.excludesfile ~/.gitignore_global
$git rm --cached <file>
to track the empty directory put .gitkeep in the empty directory
$git ls-tree HEAD
$git ls-tree master
$git ls-tree master [directory]
$git ls-tree SHACODE#[min 10character]
$git log --oneline
$git log --oneline -3
$git log --since="2017-01-26"
$git log --since="2 weeks ago" --until="3 days ago"
$git log --since=2.weeks --until=3.days
$git log --author="hemanth"
$git log --grep="file"
$git log ca834f5..03b1b6c --oneline
$git log -p
$git log -p ca834f5
$git log --format=oneline
$git log --format=short
$git log --format=full
$git log --format=email
$git log --format=raw
$git log --graph
$git log --oneline --graph --all --decorate
$git show 3c0aff9
$git show --format=oneline HEAD
$git show --format=oneline HEAD^^
$git show --format=oneline HEAD~3
$git show 994170cc939
$git diff 3c0aff9 resources.html
$git diff 3c0aff..HEAD
$git diff 3c0aff..HEAD^^
$git diff --stat --summary 3c0aff9..HEAD
$git diff --ignore-space-change 3c0aff9..HEAD
$git diff --ignore-all-space 3c0aff9..HEAD
$git diff -w 3c0aff9..HEAD
$git branch
Command to display all local and remote branches
$git branch -a
Command to display only remote branches
$git branch -r
$git branch new_feature
new_feature is new branch name
$git checkout new_feature
$git checkout master
$git checkout -b <branch_name>
$git commit -am “Swap out”
$git diff <branch_new>..<branch_new>
$git diff --color-words <branch_new>..<branch_new>
$git diff --color-words <branch_new>..<branch_new>^
$git branch --merged
$git branch -m <branch_name> <new_branch_name> (OR)
$git branch --move <branch_name> <new_branch_name>
$git branch -d <branch> (OR)
$git branch --delete <branch>
$git branch -D <branch>
Create and checkout to new_branch
$git checkout -b new_branch
After any new file and push changes to new_branch
$git push -u origin new_branch
create a pull request on new_branch
$git pull-request -b project_name:master -h project_name:new_branch
Clone a repo
$git clone deadlyvipers/dojo_rules
Change to project repository
cd dojo_rules
Fork the repo
$git fork
Add remote for upstream
$git remote add upstream <path_to_repo>
Fetch changes
$git fetch upstream
Merge them into master
$git merge upstream/master master
push to remote
$git push origin master
$__git_ps1 (OR)
$export PS1='$(__git_ps1 "(%s)") > '
$git merge <branch_name>
$git branch --merge <branch_name>
$git merge --no-ff branch <branch_name>
$git merge --ff-only branch <branch_name>
$git merge --abort
$git mergetool –-tool=gvimdiff
$git stash save “Commit message here”
$git stash list # to list out stash
$git stash show stach@{0} #This is similar to git diff
$git stash show -p stach@{0} #this is patch to git diff
$git stash pop stash@{0}
$git stash apply
$git stash drop stash@{0}
$git stash clear
For Interactive rebase use below command
$git rebase -i
To create and checkout to feature_banch and update your code here
$git checkout -b feature_banch
After updating code to rebase you should be in feature branch and use below command to merge in master branch
$git rebase master
Git rebase example command from old base to new base below
$git rebase --onto <newbase> <oldbase>
Another example command this will rebase master with server branch commit.
$git rebase master server
Light weight tag Just a tag, no message or tagger
$git tag
Signed tag Uses public key to prove identity of tagger
$git tag -s
Annotated tag Add info on tagged, when and why
$git tag -a
Example
$git tag -a v1.0.0 -m "Tag message"
Pushing tags
$git push --tags
git push origin :tagname
git push --delete origin tagname
git tag --delete tagname
$git remote
$git remote add <alias>
$git remote add origin <github address>
$git remote -v
$git reemote rm origin #to remove remote origin
$git push -u origin <branch_name>
-u is used for tracking file if is not availble it is difficult -u similar to --up-stream
$cat .git/config
$ls -la .git/refs/remotes/origin/
$ls -la .git/refs/remotes/origin/ -r
$ls -la .git/refs/remotes/origin/ -a
$git clone <gitlink> <new_directory>
$git clone https://github.com/hemanth22/explore_california.git git_version
List of commands
$curl https://api.github.com
List of emojis
$curl https://api.github.com/emojis
public info on user
$curl https://api.github.com/users/username
A users repos
$curl https://api.github.com/users/username/repos
Authorization
$curl -i -H 'Authorization: token <your_authentication_token>' https://api.github.com/user
Create a repo
$curl -i -H 'Authorization: token <your_authentication_token>' -d '{"name":"test_repo"}' https://api.github.com/users/repos
- Repository
- working
“When ever you commit changes you made in the project it generate a checksum.“
What is check sum
Checksum algorithm converts data into simple number
→ Same data always equal same checksum
Checksum algorithm is SHA-1
Which creates a 40 characters with hexadecimal (0-9,a-f)
Example : e8be9f76c3e3bf4fa8d06d4aa2ad34428e9c442b
pointer to tip of the current branch in repository Last state of repository what was last check out
Command to search keyword in the all the versions of the commit.
git grep "_source" $(git rev-list --all)
git grep "select *" $(git rev-list --all)
git grep "bank" $(git rev-list --all)
Command to give log information in detail.
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
echo "# GradeBook" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/hemanth22/repositoryname.git
git push -u origin master
git log --pretty=oneline | grep -e '[A-Z]\+-[0-9]\+' -o
git log --pretty=oneline | grep -e 'XON\+-[0-9]\+' -o
https://barro.github.io/2016/02/a-succesful-git-branching-model-considered-harmful/