Git and GitHub
Commands
Git and GitHub
Commands
- ls — listing all files and folder inside the current directory
- mkdir — creating new folder (mkdir folder)
- cd — changing directory (cd folder — going inside folder)
- git init — initializing git repository
- ls -a — show all the hidden files (.files will be hidden)
- ls .git — shows all hidden files inside .git
- touch — to create new file(touch names.txt)
- git status — to know status of the project
three stages: Untracked Stagged — git add . Committed — git commit -m “commit message”
- git add . — moving uncommitted files to staging
- git add names.txt — staging the particular file(but it will show like yet to commit)
- git commit -m “message” — committing the staged file
- git restore(space)— — staged names.txt
- this will restore to the previous stagged version
- git log — to find history
- press ‘:q’ to exit the logs
- rm names.txt — to remove file
- git reset f4954ce65fØØ456Øff74be8225763e31b41a9869 — to go back to the version we want in git
- we can remove the commit which we have done previously and it bring back to the stagged state
- if we don’t want from commit 3, we have to give git reset commit 2 code
- git stash — will make code move to backstage, whenever needed can take but it won’t be committed
- git stash pop — bring back stage to front stage
- git stash clear — removing files or folders from backstage
- git push origin branchName
- git pull origin branchName
NOTES:
Our account — origin url Project we’re fork — upstream url
// create different branches for different features because there only one pull request can be made for one branch until it is merged.
- git push origin branchName -f — this force push is used when the online repo has the commits and our repo not, then this force is needed
- git push origin branchName
Connecting project with GitHub
- git remote add origin URL — to add project to GitHub
- git — just git command
- remote — url
- add — adding new URL
- origin — name of the url we gonna add
- git remote -v — to get all the git url attached to this project
- git push origin branchName — pushing code to GitHub branch
- git branch newBranchName— to create new branch(make sure the master or main branch is upto-date before creating new branch)
- git checkout newBranchName— head is pointing towards this new branch
- For each feature create new branches so that pull request will be organized, if we gonna give multiple commit for different feature, while pulling everything will be merged as one commit. ONE BRANCH — ONE PULL REQUEST
To merge
step 1: checkout to the main branch(branch where we have to merge) step 2: git merge branchName(branch to merge) clear conflict, if present then merge
Cloning project
- first fork the project (getting other source project to your acc)
- git clone url
- git remote add origin URL — this is our branch
- git remote add upstream url — (link of original project, to get the original project linked to our project folder)
- git fetch (space) — — all (space) — — prune (to get the updated code of original upstream branch)
Methods to pull commits from upstream to origin
Method 1: Button
- Click Fetch upstream button
Method 2:
- Step 1: git checkout originMainBranch
- Step 2: git pull upstream mainBranchName
- Step 3: git push origin main
Method 3:
- Step 1: git checkout originMainBranch
- Step 2: git fetch (space) — — all (space) — — prune
- Step 3: git reset (space) — — hard upstream/main — resetting main branch of origin as same as main branch of upstream -> pulling updated code from upstream branch
- Step 4: git push origin main
Squashing the commits
- merging lot of commits into one commit . git rebase -i commitID — it shows pick, we have to pick or squash by changing the pick to s(squash), where the pick will be the commit and the squash will get merged. . to exit -> esc + :x . git reset commitID — bring all the files above that in stagging then we can commit as a single commit— alternative method . git reset commitID(space) — — hard — this will delete permanently, even in stagging will get deleted.
Editing file using Vim
step 1: vi names.txt step 2: insert step 3: edit the things u want step 4: to close -> esc + :x
Viewing the content in the file cat names.txt
메타데이터
- post_id
- fcc8a7ac204c
- slug
- git-and-github-fcc8a7ac204c
- url
- https://medium.com/@ishavenkadesh03/git-and-github-fcc8a7ac204c
- canonical_url
- https://medium.com/@ishavenkadesh03/git-and-github-fcc8a7ac204c
- author_url
- https://medium.com/@ishavenkadesh03
- status
- ok
- fetched_at
- 2026-06-23 03:48:11