Git Commands

Basic Commands

Commands
Command Description
git --version Check git version
git command -help / git command --help / git help --all Git help option for specific command / Git help option for all possible commands
git config --list Configure user information for all local repositories
git config user.name / git config --global user.name Configure user information for all local repositories
git config user.email / git config --global user.email Configure user information for all local repositories
git config user.password / git config --global user.password Configure user information for all local repositories
git config --global core.autocrlf true Configure user information for all local repositories
git config --global core.safecrlf true Configure user information for all local repositories
git config --global color.ui auto Configure user information for all local repositories
git config --global init.defaultbranch Configure user information for all local repositories
pwd Print working directory
mkdir directoryname Make a new directory
cd directoryname Change the current working directory
ls / ls -lart / dir List the files in the current working directory / List the files and directories in the current working directory / List the directories in the current working directory
git init Turn an existing directory into a git repository
git branch Check the current git branch
touch .gitignore Make the .gitignore file
git status / git status --short Check git status / Check the compact version of the status
git add filename / git add --all / git add -A Add untracked file to staging environment
git commit -m "what changed and when message" / git commit -a -m "what changed and when message" Add tracked/stage files to commit environment
git log Check the history of commits
git remote add origin url It specifies that you are adding a remote repository, with the specified url, as an origin to your local git repo
git push --set-upstrem origin master / git pull --set-upstrem origin master To push our master branch to the origin url, and set it as the default remote branch / To pull our master branch to the origin url, and set it as the default remote branch
git fetch origin Fetch gets all the change history of tracked branch/repo
git log origin/master If changes tracked then check the change by log
git diff origin/master Verify by showing the difference between our local master and origin/master
git merge origin/master Merge our current branch master with origin/master
git push origin / git pull origin It is Used to push all changes to our remote origin / It is used to pull all changes from a remote repository into the branch you are working on.

Remote Commands

Commands
Command Description
git remote To configure remote, or change the name of remote
git remote -v To configure remote, or change the name of remote
git remote rename oldremote newremote To configure remote, or change the name of remote
git remote remove name To configure remote, or change the name of remote

Branch Commands

Commands
Command Description
git branch Check the current git branch
git branch branchname Create new branch
git checkout branchname Change the branch
git checkout -b branchname Create new emergency branch
git merge branchname Merge the two branches
git branch -d branchname Delete new branch
git branch -a It is used to see all local and remote branches
git branch -r It is used to see all remote branches only
git merge branchname Merge the two branches
git push origin branchname To push the branch from our local git repository to remote github repository

Cloning Commands

Commands
Command Description
git clone url / git clone url directoryname To clone the repository in your local machine / To clone the repository in local machine or which folder

History Commands

Commands
Command Description
git log Check the history of commits
git log origin/master If changes tracked then check the change by log
git diff origin/master Verify by showing the difference between our local master and origin/master
git fetch origin Fetch gets all the change history of tracked branch/repo