krantikr
Posted on November 27, 2019
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.
what is Git?
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.
Table Of Contents
git config
git init
git status
git fetch
git branch
git checkout
git add
git commit
git push
git pull
git diff
git stash
git merge
git reset
git cherry-pick
#git config
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
#git init
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
#git status
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.
git status
#git fetch
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
#git branch
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
#git checkout
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
#git add
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
#git commit
The git commit command is basically used to commit our code and log message about it.
git commit -m "comment"
#git push
The git push command is basically used to push our changes to the remote.
git push
#git pull
The git pull command is basically used to pull out all the remote changes to our local.
git pull
#git diff
The git diff command is basically used to see your local changes line by line.
git diff
#git stash
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.
#git merge
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.
#git reset
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.
#git cherry-pick
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.
Posted on November 27, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.