Michelle Buchi Okonicha
Michelle Buchi Okonicha's Blog

Follow

Michelle Buchi Okonicha's Blog

Follow
Git, GitHub and Git Commands

Git, GitHub and Git Commands

Michelle Buchi Okonicha's photo
Michelle Buchi Okonicha
·Aug 19, 2022·

9 min read

**WHAT IS GIT? **

A lot of times, people are confused on the right commands to use to resolve git issues and the steps to take in resolving those issues. Hence spending more time researching, trying, and working. This takes time, reduces code time and increases the complexity of work.

Git is a version control software that is free and open source used to track changes in any set of files and to manage projects from small to medium to large projects. It helps to coordinate work amongst programmers and is efficient, fast and supports distributed and non-linear workflows.

Git can be accessed on all PCs from Windows to mac to Linux. Git tracks files, contents, and coordinates projects.

DIFFERENCE BETWEEN GIT AND GITHUB

Git is a version control software that tracks and manages contents, files and projects while Github is a cloud-based hosting service used to manage git repositories. So, in essence, github manages git repos but git provides the tracking and coordinating service hosted on github. Git repositories are generally local repos and can be stored in the cloud using github. So basically, github is a tool for working with git. There are other services to host git. They include: Bitbucket, GitLab, Perforce, Beanstalk, Amazon AWS CodeCommit, Codebase, Microsoft Azure Devops, SourceForge.

Another difference is in the ownership: Github is owned by Microsoft Corporation while git was built by Lins Torvalds, the creator of Linux.

GIT COMMANDS

There is a long list of git commands available to git users regardless of the git hosting service being used.

1. git config -1: This command returns a list of information about your configuration. It includes name and email.

2. git config –global user .email “”: This lets you set up the user email address you want to use in your commits.

3. git config –global user .name “Mimi”: This command is used to configure your user name.

4. git config –global credential .helper cache: It helps you store login credentials in the cache so you don’t have to type them in every time.

5. git init: This is usually the first command you use when working with repos. It is used to initialize a new git repo locally in your project root.

6. git add filename_here: This command helps you add a file to the staging area. Replace the ‘filename_here’ with the file you want to add.

7. git add . : This command is used to add all your files in your project to the staging area. The . indicates adding every file.

8. git add mic :* This command helps you add files starting with mic. You can input any string/values. The asterisk is the search feature that helps find files.

  1. git status: This command shows the status of the current repo including staged, unstaged and untracked files.

10. git commit: This command will open a text editor in the terminal so you can write a full commit message. A commit message is a short summary of changes, an empty line and a full description of the changes after it.

11. git commit -m “write your commit message here”: This command helps you specify a short summary for your commit without the text editor and also, it commits all added files.

12. git commit -a -m “ your commit message here”: This command helps you add as well as commit tracked files in one command by using the -a and -m options.

13. git log: This command shows the commit history for the current repository.

14. git log -p: This command history including all files and their changes.

15. git show commit-id: This command shows a specific commit. Replace the ‘commit-id’ with the id of the commit that you find in the commit log after the word commit.

16. git log –stat: This command will cause the git log to show some statistics about the changes in each commit, including line(s) changed and file names.

17. git diff: This command helps to show only unstaged changes by default. You can pass a file as a parameter to only see changes on a specific file. We can call diff with the –staged flag to see any staged changes. ‘Git diff, git diff all_checks.py, git diff –staged.

18. git add -p: This command opens a prompt and asks if you want to stage changes or not and includes other options.

19. git rm filename: This command expects a commit message to explain why the file was deleted.

20. git mv oldfile newfile: This command helps stage changes then expects a commit message.

21. .gitignore: This is a file created in your folder/repo to ignore files in git.

22. git checkout filename: This command is used to revert unstaged changes in git.

23. git reset HEAD filename, git reset HEAD -p: This command is used to revert staged changes in git.

24. git commit –amend or git commit -a: This command is used to allow you modify and add changes to the most recent commit.

25. git revert: This command is used to rollback the last commit in git. It will create a new commit that is the opposite of everything in the given commit. ‘Git revert HEAD’

26. git revert commit_id_here: This command is used to revert an old commit using its commit id. It opens the editor so you can add a commit message.

27. git branch branchname: This command helps you create a new branch. By default, you have one branch, the main branch. You can however create a new branch. Git won’t switch to it automatically. We would need to switch to it.

28. git checkout branch_name: This command helps you to switch to another branch. After creating a new branch, you can switch over.

29. git branch: This helps list out the available branches for that project and it marks the current branch with an asterisk and highlights it in green.

30. git checkout -b branch_name: This is used to create a new branch as well as switch over to the new branch immediately.

31. git branch -d branch_name: This command helps you delete a branch from in git. When you are done working on a branch and have merged it, you can delete it using the command.

32. git merge branchName: This command is used to merge the history of the branch you are currently in with the branchName branch.

33. git log –graph –oneline: This command is used to show the commit log as a graph in git. –oneline will limit commit messages to a single line.

34. git merge –abort: This command is used to abort a conflicting merge in git. If you want to throw a merge away and start over, you can run this command.

35. git add remote repo_here: This command adds a remote repository to your local repository(replace the repo_here with your remote repo URL).

36. git remote -v: This command shows you all remote repositories for your local repository.

37. git remote show origin: This command shows more info about a remote repo in git(replace origin with the name of the remote obtained by running git remote -v).

38. git push: This command is used to push changes to a remote repo in git.

39. git pull: This command is used to pull changes from a remote repo in git.

40. git branch -r: This command is used to show the name of all remote branches that git is tracking for the current repository.

41. git fetch: This command will download the changes from a remote repo but will not perform a merge on your local branch(as git pull does that instead). It fetches remote repo changes.

42. git log origin/main: This command is used to check the current commits log of a remote repo in git.

43. git merge origin/main: This command is used to merge a remote repo with your local repo in git.

44. git remote update: This command is used to get the contents of remote branches in git without automatically merging. It lets you update the remote without merging any content into the local branches.

45. git push -u origin branchName: This command is used to push a new branch to a remote repo in git. -u creates the branch upstream.

46. git push –delete origin branch_name_here: This command is used to remove a remote branch in git. If you no longer need a remote branch you can remove it using the command below.

47. git rebase: This command is used to transfer completed work from one branch to another. Git rebase can get really messy if you don’t do it properly. Read the official documentation before using it.

48. git rebase -i master: In order to run git rebase interactively, you include the -i flag. It will open the editor and present a set of commands you can use.

**49. git push -f: **This command is used to force a push request. This is usually fine for pull request branches because nobody else should have cloned them but this isn’t something that you want to do with public repos.

50. git reset –soft HEAD^: This command sets HEAD to the previous commit and leaves changes from the undone commit in the stage/index.

51. git bisect: This command is used to compare the buggy commit to an early commit that works as expected.

52. git rebase -i HEAD~10: To list the last 10 commits and modify them with either the squash or fixup command.

53. –global: This command is used to apply got configurations across your entire git environment.

54. git rebase: This command is used to squash multiple commits together without using git merge -squash.

55. git commit -a -m “Refactor code base”: This command is used to add all modified files to the staging area, then commits them with a message.

56. git pull -all, git pull -u origin master, git reset –hard master, git pull origin master: This command is used to force an overwrite of your local files with the master branch.

57. git add -A: This command is used to stage all new and updated files.

58. Git show refs/head/push-notifications: This command is used to specify the exact branch when it has a similar name to another project.

59. git rebase -i: This command gives the list of all commits that should be moved before rebase.

60. git-bisect: This command is used to perform binary search using a known bad commit and known good commit to determine which commit introduced a bug.

**61. -amend: **This command helps you modify your previous commit.

62. git rm –cached file.js: This command will remove the file.js from the staging area and its changes no longer tracked.

63. git stash: This command is used to save your work and return later while attending to move to another branch.

  1. The language used in git is** C.**

65. git diff -cached: This command is used to review a series of staged changes to the index before commit.

66. git stash drop: This command is used to remove the most recent stash entry.

67. git reset file.txt: This command is used to remove files from the index that were mistakenly staged to the index.

68. git help reset: This command helps you see a description of available options before git reset.

69. git merge-abort: This command is used to abort a merge that is already ongoing and to restore it to its pre-merge state.

70. git tag v3.8.1: This command creates a lightweight tag.

71. git prune –expire : This command is used to delete unreachable objects older than a specified time from your project database.

72. git clean -f: This command is used to remove untracked files from the working directory.

73. git push –force-with-lease: This command is used to manually push changes regardless of merge conflict.

74. it stash show-p stash@{2}: This command is used to see the details of stashed changes in the first of the three stash entries.

My Twitter Handle: https://twitter.com/mchelleOkonicha

My LinkedIn Handle: https://www.linkedin.com/in/buchi-michelle-okonicha-0a3b2b194/

 
Share this