Git and GitHub (Part-2)

Syeda Nowshin Ibnat
5 min readFeb 19, 2022

--

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.

Photo by Roman Synkevych on Unsplash

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.

Git Remove:

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.

21. Command:

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.

Merge Commands:

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:

Solution:

  • 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).

Push:

29. git push origin main (it will push all folder and their changes in remote my GitHub account).

Fetch:

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.

Pull:

31. git pull → to do fetch + merge together.

i) Problem:

Solution:

git help → to get help and see the necessary things.

Reliable Resources:

https://www.geeksforgeeks.org/ultimate-guide-git-github/

https://www.simplilearn.com/tutorials/git-tutorial/what-is-github

https://youtu.be/oe21Nlq8GS4

https://youtu.be/SWYqp7iY_Tc

© Syeda Nowshin Ibnat

--

--