Git-Commands 🤞

aryan inglearyan ingle
3 min read

Problems That I encountered :

  1. Mostly the problems that I encountered while learning git are not real problems rather I would say that they are mistakes that I did because of my half knowledge of what I was trying to do . And I hope any new beginner does not do this mistake again , so read the blog to get wise from my mistakes .

  2. 1st mistake : Tried to push files from a different local repo(A_repo) to a remote repo(B_repo). Which is not possible as far as I know . So you can push files from local -> B_Repo to remote->B_Repo only ; that is when you have cloned the remote->B-Repo to your computer i.e, Local->B_Repo.

  3. I tried directly pushing the Local->B_Repo to remote->B_Repo , that is a mistake, because :-

    1. Should check if the remote->B_Repo's branch(in which you are trying to push) is already updated and the Local->B_Repo which you are trying to push is actually pre dated or older update . Soupdate your Local->B_Repo using :

      git pull --no-rebase origin main

      It will update the Local->B_Repo

    2. I tried out of curiosity , so the Local->B_Repo is updated w.r.t remote->B_Repo now if we commit in local repo , then it is 1 commit ahead right? So if then I try to push it gave me this :-

      Everything up-to-date

      Not correct so I learned a command to check the status of local->B_Repo in comparison to remote->B_Repo :

      git status /or git status -uno

      -This helped me to see the status as :

      So next to push this changes i did the below followed things :

  4. At last when I saw my remote repo i saw the changes .

Commands I used :

git rebase main

git remote -v

git push origin [branch name]

Push a branch to your remote repository

git branch -d [branch name]

Delete a branch

git branch [branch name]Create a new branch
git branch -aList all branches (local and remote)

git rm -r [file-name.txt]

Remove a file (or folder)

git commit -m "[commit message]"

Commit changes

git branch

List branches (the asterisk denotes the current branch)

git add -A

Add all new and changed files to the staging area

git add [file-name.txt]

Add a file to the staging area

git statusCheck status

git init

Initialize a local Git repository

git clone ssh://git@github.com/[username]/[repository-name].git

Create a local copy of a remote repository

git pull --no-rebase origin main

git add .

-r : to see the remote branches

-a: see local +remote branches

*: current active.

git merge [source branch] [target branch]

Merge a branch into a target branch

git merge [branch name]

Merge a branch into the active branch

git checkout -

Switch to the branch last checked out

git checkout [branch name]

Switch to a branch

What I Learned :

  1. All the above are my exploration learnings .

  2. I learned how to read solutions from stack overflow atleast I have started to read sometimes there are too many solutions and get confused in between choosing which one is the proper solution to execute.

  3. Next I learned to command prompt more efficiently and various linux + git cmmds

  4. Starting to understand what it is like to ask the correct technical questions and optimize the need of optimized prompt engineering .

  5. Got to know what are the uses of various git commands .

  6. How to write a blog on the real time problem simultaneously solving it .

1
Subscribe to my newsletter

Read articles from aryan ingle directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

aryan ingle
aryan ingle