10 Useful git commands for beginner developers

Rahul Mishra- June 23, 2022
    1. Create a git branch
      git checkout -b branch-name


    1. Pull from remote overwriting local changes
      1. git stash (revert and stash changes locally)
      2. git pull (pull from remote normally)
        tip: to retrieve changes, do ‘git stash apply


    1. Delete untracked files from the working tree
      git clean -f -d


    1. Unstaged files from the index (but keep the files locally)
      git rm –cached


    1. Undo a merge
      1. git checkout branch-name
      2. git log –oneline
      3. git revert -m commit-id


    1. Remove a file from remote
      1. git rm filename (remove the file from git)
      2. git commit -m “commit message”
      3. git push


    1. Undo last n commits
      git reset –soft HEAD^n (where n is the number of last commits you want to undo)


    1. See diff between branches
      git diff branch_1..branch_2
    2. Remove a tag from the branch
      1. git push origin :refs/tags/tagname
      2. git tag -d


  1. Rename a branch locally & remote
    1. git checkout old-branch
    2. git branch -m new-name
    3. git push origin :old-name new-name

I have taken a reference from this Tweet.

Similar Artcles

Avoid These 5 Mistakes to Never Go Wrong With Node.Js Development
read more
10 Useful git commands for beginner developers
read more
Top 10 Reasons – Flutter Is Better For Your App Development
read more