Table of contents
Git - developed by Linus Torvald in 2005 is a Distributed version control system. In distributed version control system, every person will have their own server which means they'll a copy of entire history of code locally.
3 stages of git -
Working directory / Workspace
Staging
Local repository
When we commit, a commit ID is generated.
Branch -
When people are simultaneously working on a single project, we've to assign them various tasks without disturbing the flow of project.
When a branch is made, all works present at that particular stage, would be copied, and then people can work on it. (Add / Delete )
Basic Commands
git clone - It creates a copy of an existing Git repository on our machine.
git log - Shows commit history.
git push - Copies changes from the local repository to the Remote / Central repository.
git pull - Copies changes from the Remote / Central repository, to local repository. Used for synchronization between 2 repositories.
git checkout - Used to Switch to another branch
git merge - To combine branches.
git add - Moves changes from the working directory to the staging area
git commit - To save changes made in the local repository.
git init - Initializes a new Git repository.
git branch - To create a branch.
git remote - Used to create, view, and delete connections to other repositories.
Advance commands
git rev-list --all | xargs git grep -F ' ' - Searching for a specific string inside git repository or in your commits.
git rev-list --count - To show the no. of commits made in that particular branch.
git branch --merged | grep -v "branch name" | xargs -n 1 git branch -d - clean up local branches, deleting them all at once instead of deleting them one by one.
git show : - To look for a file in some other branch without switching the branch.
git commit --allow- empty -m 'new empty commit' - To do an empty commit. This command is useful when you want to trigger a build by committing something, so instead of editing things unnecessarily inside files to commit, we do a empty commit.
git config --global help autocorrect 1 - To auto - correct spelling mistakes.
git config --global fetch.prime true - To prune orphaned objects.