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.

git init

2. To see all the branches in the current repo along with the current branch :

git 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 :

git status

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!

Related Posts

Comments ( 3 )
  1. muri
    June 21, 2016 at 1:36 pm

    thanks for the nice summary!
    i think it should be ‘git remote add’ instead of ‘git add remote’
    btw, not sure if you’re aware: your blog can only be viewed with javascript enabled…

    • keerthana
      June 21, 2016 at 5:11 pm

      You’re right! Thanks for pointing it out! I just corrected it

  2. Homepage
    July 9, 2016 at 2:22 pm

    … [Trackback]

    […] There you will find 60426 more Infos: thewaterbabe.in/2016/06/20/10-git-commands-every-developer-should-know/ […]

Leave a reply