In this tutorial , we will see some of frequently used git commands which can be run on command line.
I am assuming that git is installed , configured with your credentials and cloned the repository into your local machine. Now lets see the commands which a developer uses for check in and checkout of code on daily basis.
Create a local branch
git branch new-branch-name
Above command will create a branch locally. Until you checkout this branch and push it, it will not be available remotely.
Show the list of branches
git branch --list // lists all local branches git branch --list -r // lists all remote branches git show-branch // lists all local and remote branches
Checkout an existing branch
git checkout existing-branch-name
Above command will switch or restore the branch to given existing branch.
Create and Checkout branch in single command
git checkout -b new-branch-name [existing-branch]
It will create a new branch and base branch will be the given existing branch.
Check the status of branch and file changes
It will show the current branch name and both new and modified file list.
Stage the changes
git add filenames-with-changes
Staging of changes means preparing them for commit. Until you stage the changes using this command, same cannot be committed to a branch.
Commit the changes to current branch
git commit -m commit-message
This command would commit the current changes which you have seen through status command to the current branch.
Push the changes to remote repository
git push origin branch-name
Pushes the branch with changes to remote repository.