Sakib's Blog

Sakib's Blog

Getting Started With Git Commands

As a software engineer, we need to collaborate on multiple projects with the engineering team. For that, Git is one of the most used and recommended Version controlling system that the industry is using on a daily basis. Therefore, at the early stage of my engineering career, I also needed to know the basic commands of git in order to have a better synchronization with the team and the projects we will be working on.

Today I will be sharing my knowledge on git and its commands to get started with your initial projects.

There are 4 stages:

  1. Workspace : This is the folder/Location/Directory where we start our project.

  2. Staging : Making candidates to be committed to the local repository.

  3. Local Repository : After staging, we need to commit changes to here.

  4. Remote Repository : After committing, we can push our changes to the Remote Repository.

Now, Lets Explore the commands to work on all the above mentioned steps.

  1. To initialize a new local repository in your workspace :

     git init
    
  2. To configure user globally

     git config --global user.name "name"
     git config --global user.email "mail"
    
  3. To configure user specifically for specific project

     git config user.name "name"
     git config user.email "mail"
    
  4. To see the config
     git config --list
    
  5. For Staging
     git add --all
     git add .
     git add filename
    
  6. For commit
     git commit -m "msg"
    
  7. To see all commit details shortly
     git log --oneline
    
  8. Going back to previous Stage
     git checkout 'CommitCode'
    
  9. See changes of a commit
     git show ‘CommitCode’
    
  10. See difference between 2 commits
    git diff commit1code commit2code
    
  11. To remove a file from git
    git rm file.txt
    
  12. Delete a file from Workspace
    git rm filename
    
  13. Remove a file from Staging (Untrack)
    git reset HEAD filename
    
  14. Create New Branch
    git branch branchName
    
  15. See All Branches
    git branch
    
  16. Switch branches
    git checkout branchname
    
  17. Create branch and switch to that branch
    git branch -b branchName
    
  18. Let Local Repo know that there is a change in Remote repo
    git fetch
    
  19. Get the changes of Remote in Workspace
    git pull
    
  20. Merge 2 branch (From present branch)
    git merge OtherBranchName
    
  21. Save the file to temporary folder, So we don't loose that
    git stash
    
  22. Get the file from stash
    git stash pop/apply
    
  23. List of stash
    git stash list
    
  24. Go to specific Stash
    git stash pop stashCode
    
  25. Remove untracked Files
    git clean -f
    
  26. To Ignore a file
    Create a .gitignore file
    touch .gitignore // will create the ignore file.
    
  27. Use HTTP Link to connect with remote repository.
    git remote add origin httpLink
    
 
Share this