In this developing and fast-growing technology world, it is very important that how you keep all your code and your changes save so to solve this problem Git came to the picture where you can keep your all code changes version wise safe. Basically, with the help of Git, you can track your code changes. In this blog, we are just going to discuss some of the terminal comments for Git that will always help you in day to day life. You can do the same things with Git Tools UI but I prefer to do these things from the command line because doing things in the command line is cool and faster.
Git is a free and open-source distributed version control system. Git’s purpose is to keep track of projects and files as they change over time with manipulations happening from different users. Git stores information about the project’s progress on a repository. A repository has committed to the project or a set of references to the commits called heads. All this information is stored in the same directory as the project in a sub-directory called .git and will mostly be hidden by default in most systems.
The git config command sets the author's name and email address. Whatever you will set here that will appear with your commits.
git config --global user.name "[name]" // To set author's name git config --global user.email "[email]" // To set email address
The git init command creates a new Git repository. You can use this to convert your existing project to a Git repository or initialize a new repository.
git init repository_name
The git status command displays the state of the working directory. You can check your branch, all your files whichever has changed or added and also you can check how many commits you have to push whatever you have committed but not pushed.
The git fetch command basically refers from a remote repository into your local repository.
git fetch remote_name branch_name // will only fetch the changes from that remote branch git fetch remote_name // will only fetch the changes from remote origin git fetch --all // will fetch all branches from all remotes
The git branch command basically shows you a list of branches.
git branch // list of all your local branch git branch -r // list of all remote branches git branch -a // list of all local and remote branches
The git checkout command always allows you to switch into a different branch, create a new branch or reset your file changes.
git checkout branch_name // checkout into a different branch git checkout -b new_branch_name // create a new branch and switch into that git checkout file_path // reset all your change from that file git checkout . // reset all your file change
The git adds command is basically used to add your local changes.
git add . // add your all local changes git add directory_path // add all changes from a particular directory git add file_path // add your changes from a particular file
The git commit command is basically used to commit our code and log message about it.
git commit -m "comment"
The git push command is basically used to push our changes to the remote.
The git pull command is basically used to pull out all the remote changes to our local.
The git diff command is basically used to see your local changes line by line.
The git stash command is used to stash all our local changes from the current working directory and adds to the stash list.
git stash // Stash the changes. git stash list // list the stash entries that you currently have. git stash pop // remove a single stashed state from the stash list and apply it on top of the current working directory git stash apply // like pop, but do not remove the state from the stash list. git stash clear // remove all the stash entries.
The git merge command is used to join branch changes into one. For merge first checkout with your branch where you want to take all the other branch changes then apply merge command.
git merge --abort // can only be run after the merge results in conflicts. it will abort the merge process and try to reconstruct the pre-merge state. git merge --no-ff branch_name // create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward.
The git reset command is used to return the entire working directory to the last committed state.
git reset --hard // will remove the last commit from the current branch, and your working directory git reset --soft // will remove the last commit from the current branch, but the file changes will stay in your working directory.
The git cherry-pick command is used to take out some commits from one branch and add it to another branch.
git cherry-pick commit_id git cherry-pick commit_id -x // cherry-pick with all the commits message
I have written this blog to just remember all the commend that we are using in our day to day life, if I have missed anything then feel free to add that in the comment. I will appreciate all your comments and suggestions.