10 Git commands every developer should know
Git is a version control system which is very common among developers. I’m not going to explain how git works, because there are plenty of great introductory tutorials on the internet for that. However, I would like to documment the commands I frequently use
1. First, we initialize a git repo. Take care to ensure that you initialise the repo in the folder where all the files you want to commit exists.
2. To see all the branches in the current repo along with the current branch :
To create a new branch :
git branch <branch_name>
3. To change branches :
git checkout <branch_name>
If the branch doesn’t exist, it can be created by using :
git checkout -b <branch_name>
4. To see the status of the files, ie. if there are uncommitted changes, files to save etc.. use :
5. To stage the changes in the directory for the next commit, use :
git add <filename>
To stage all files in a directory
git add .
6. To commit the staged changes in the directory, use :
git commit -m "<commit_message>"
7. To create a new connection to a remote repo, especially to push existing code to a Github repo :
git remote add <connection_name> <connection_url>
8. To push the code into the remote repo
git push -u <connection_name> <branch_name>
9. To get the contents of a repo
git clone <path>
10. To merge another branch to the current (Example: a side branch to the master)
git merge <branch_name>
For a more detailed list of git commands for easy access check out this nifty cheat sheet. Happy coding!