Git Commands Basics
Git is a distributed version control system. Like other traditional version control systems it saves the versions of a project with modification details. But unlike others, git maintains a local repository for every project.
There are mainly 3 git stages for a file in a local computer:
Un-tracked : File in working area
Staged: File in staging area
Committed: File committed to local repository
Basic Git Commands
git init: To make a local folder to a git working area.
git status: Used to understand what stage the files in repository at.
git clone <remote_repo_url>: To clone a remote repository into local working area.
git add <file name> : To add a file to staging area.
git commit -m '<message>': Commits the file from staging area to local repository.
git push: Pushes the committed file from local repository to remote repository.
git log: Shows logs of all commit history.
git log --oneline: Shows commit logs in a single line.
git difftool | HEAD: Shows the differences in the files from previous version.
git branch <branch name>: Creates a new branch from the master (A git branch is a copy of complete project where you can add new changes can be made).
git checkout <branch name>: Changes the head to the new branch.
git push origin <branch name>: Pushes the branch changes to remote.
git merge <branch name>: Merges the branch changes to master (remote) branch.
git -d <branch name>: Deletes a branch.
git rebase: Renounce the changes committed in branch, and reflects the master changes in branch.
git revert: Reverts the changes in a commit.
git reset: Deletes commit and changes history.
git show HEAD: To view changes made in the last commit.
git pull origin master: To merge changes from the remote repo.
git checkout <file name>: Replaces the file in the working directory to last committed version.
Git Rules
Create a new Git repository for every new project.
Create a new branch for every new feature.
Delete every branch created after merge.
Write a good descriptive commit message.
Use pull request to merge your code with master.