Git Commands

Git commands:

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed git remote repository.

https://cloudaffaire.com/git-remote-repository/

We are almost done with our introductory series on Git. In this blog post, we will list all the commands that have been used so far in this series.

Git commands:

#check git version
git version

#initialize git local repository
git init

#initialize git local repository with directory
git init <directory>

#check git status
git status

#getting help from command line
git help

#list all git commands and sub-commands
git help -a

#getting help for a particular git command
git help <command> # for example git help init will list details for git init command.

#add a file in staging area
git add <file>

#add all in staging
git add .

#commit a change
git commit -m "<commit message>"

#get difference between staging area in working tree
git diff

#get difference between local repository and staging
git diff --stage

#check the log
git log --oneline

#get the logs
git log --all --decorate --oneline --graph

#check logs
git reflog

#create a alias for above command
alias graph="git log --all --decorate --oneline --graph"

#discard the change in working tree
git checkout -- <file>

#discard changes in staging area
git reset HEAD <file>

#restore the file file1 from local repository (file1 will be restored to working tree and staging area)
git checkout <hash> -- <file>

#add your user name and email to git config
git config --local user.name "Debjeet"
git config --local user.email "debjeettoni@gmail.com"

#create a branch
git branch <branch>

#list all branches
git branch

#switch to another branch
git checkout <branch>

#check difference between two branches
git diff <source_branch>..<target_branch>

#merge two branches
git merge <source_branch> <target_branch>

#check which branch are merged with which one
git branch --merged

#delete a branch
git branch -d <branch>

#rename current branch
git branch -m <new_branch_name>

#git rebase
git rebase <source_branch> <target_branch>

#edit the last commit message
git commit --amend

#edit multiple commits
git rebase -i HEAD~4

#clone the remote repository
git clone https://github.com/CloudAffaire/mygit.git

#add remote repository to existing local repository
git remote add origin https://github.com/CloudAffaire/mygit.git

#check remote repository
git remote -v

#push the changes to remote repository
git push

#push a particular branch from local repo to remote repo
git push --set-upstream origin <branch>

#pull the changes from remote repository
git pull

#pull a branch from remote repo to local repo
git pull origin <branch>

#delete a remote repo branch
git push origin --delete <branch>

To get more details on git, please refer below git documentation

https://git-scm.com/doc

 

Leave a Reply

Close Menu