GIT for dummies
If you are starting with git
it is highly possible to be overwhelmed by all the commands you have to remember to work. I won't be explaining how you can install git and what is the need for git, rather jump into the commands which you need to use when you are starting as a newbie.
Before looking into the commands I hope you are having git
installed, if not please following the official link and download and install.
git --version
- Shows you ifgit
is installed in your system and also if the version of git.git init
- Initialises a new repository in the folder where you want to enable version control.git status
- Check the status of the current repository, all the changes you have made in the repository, branch name, etcgit add .
- Move all changes from unstaged area to stage area to make a commit.git add <fileName1> <fileName2> <folderPath>
- Move only the specific files or files inside the given folder from unstaged to the staged area to commit.git commit -m "<commit message>"
- Commit all the file changes which are added to the staged area with a short message.git commit -am "<commit message>"
- Notice the small change-am
, this is the combination of the above 2 commands, it adds all the files which are tracked and have been changed and commits the changes along with the message.git stash
- Stash away the changes locally. This is helpful to move between branches while you are in the middle of some work, and your work is not ready to be committed into the git.git stash list
- list out all the stashed changes you have done in the pastgit stash pop
- Retrieve back the latest stashed changes into the current working state.git branch <branch name>
- Create a new branch from the current state of the repository, i.e. from the current branch you have checked out or any particular commit.git checkout <branch name>
- Checkout to the entered branchgit checkout -b <branch name>
- This is the combination of the above 2 commands, it would create a new branch and then checkout to the newly created branch.git clone <remote url>
- Clone the repository from the remote server, like Github, Gitlab, Bitbucket, etc.git fetch
Get the metadata information from your remote origin, without actually retrieving any actual code. This is helpful when you want to know what are the latest changes in the repository before actually getting those changesgit pull
- Get the latest changes from the remote repository to the local.git push <remote name> <branch name>
Would push all the local changes you have committed to the remote repository. For eggit push origin master
.git log
shows you all the commits you have done in the past into the repository.git diff
shows you all the changes which are not committed. Helps you identify all the updates you make before committing the actual code.git merge
- Merges 2 branches locally.
These are few basic git commands which are helpful to get you started without getting overwhelmed by all the git commands present out there. Though these are the basic commands which we use most of the time and a good starting point for anyone to start with, I would highly recommend one to do a git course which I had done during initial days of my career which cleared all my concepts.