getting git ready
2 min readOct 3, 2023
Learning git offers a wide rage of benefits. Apart from the the fact that it allows you to version control software, the main benefit of git is COLLABORATION.
I truly understood its importance after working in a agile software development team, so I highly recommend learning in a collaborative project setting.
Although there are a lot of git commands to learn, I’m listing down the most frequently used commands. These will get you up and running as soon as possible.
Lets go!
- git init: Initializes a new git repository in a directory. Use this if you are starting off a new project and you want to track it in your local repository.
- git clone: This commands creates a copy of a remote repository on your machine.
- git add: This command is used to stage changes into the current branch. You can either specify individual files or folders or you can stage all chages by using $ git add .
- git commit: this command records the staged changes with a message.
$ git commit -m “Work in Progress” - git status: This gives you a snap shot of your current directory. It show files that are staged vs not staged.
- git log: Displays all commits made in the past chronologically. This information can be used to jump to previous versions of the current branch
- git branch: lists all branches in the repository. This command can also be used to create or delete branches
- git checkout: lets you switch branches or commit (from commit history that can be read from git log)
- git pull: Gets all changes from a remote repository and merges the code with the current branch you are in.
- git push: Updates the remote repository with the commits made in the local repository
- git merge: Combines changes from one branch to another. For instance if you want to merge changes from a feature branch to a production branch, you would switch to the production branch and then $ git merge feature-branch
- git diff: Shows difference in code between commits
- git reset: This is used to unstage a file. There are two types of resets
$ git reset — soft <commit_hash> preserves changes from the current commit and switches to a specified commit hash
$ git reset — hard <commit_hash> discards changes from the current commit and switches to a specified commit hash - git stash: git stash as the name suggests, store the changes on a branch into a cache, allowing you to do other operations like switching branches or pulling from a remote repository
$ git stash save “message”: stashes changes with a message
$ git stash pop: applies the most resent changes in the stash list