Git and GitHub (Part-2)
In part-1 we got to know about Git, GitHub and about some basic commands. In this part, we will see some more commonly used commands.
Carry changes from Stage to Local Repository (Commit):
16. git commit –m “I have made some changes”
(m → flag “give a summary”, it’s a good practice).
All the things are signed in the repository.
17. git reset HEAD~ → to change the files from remote to local after committed). This is call ruleback.
18. git reset --hard → to get back the hard file/physical file that I deleted earlier from a folder.
19. git rm two.txt → by using this command we can delete the file as well as can pick it to stage. But manually we have to do these two tasks separately.
20. Now if I make some changes inside the file: two.txt and want to remove it, then I will not be able to do it. I have to add –f then → forcefully delete.
Gives the change to the stage but did not delete it from the actual working directory (two.txt).
22. git rm –r folder ( r → recursive, to remove the folder inside this folder/git rm folder (to remove folder).
Branching with Git:
23. git branch (to see how many branches I have).
* main → currently I am in this branch.
24. git branch branch name → to create a branch.
25. git checkout development → switch from one branch to another.
Now, suppose we create a new file (ex: three.txt) and made a change inside it (wrote: three) and did commit, if we go back to the main branch then we will not be able to see the three.txt file there. (Git controls these things).
→ Other branches except the main are like rafh branch. We can do our work there. And after completing our work, we have to merge other branches with the main branch.
26. git merge main –m “merging on development with main” (to merge two files).
27. git merge development –m “merging on development with main” (to merge two files).
28. Merge conflict → generally merge conflict happens when two people change file.
Keep the desired one:
- Bring changes from the local repository → Remote (push).
- Bring only changes from the Remote → local repository (fetch).
- Bring only changes (fetch), merge everything to the working directory → Pull (git fetch + git merge).
29. git push origin main (it will push all folder and their changes in remote my GitHub account).
30. git fetch (to fetch the changes from the remote → working directory (here we will not be able to see the changes in the file).
git merge → it will merge and we will be able to see the changes.
31. git pull → to do fetch + merge together.
git help → to get help and see the necessary things.
© Syeda Nowshin Ibnat