Trying to Understand Git

I have a local git repo. I can run git status and see that there are untracked files with changes and new files. Since doing the steps that created my repo, I’ve been editing file names in my local project folder, adding new files, as well as editing file content. Those changes need to be applied to the local repo. Because I don’t have a good understanding of using git commands, I’m unsure how to proceed to update the repo. I want to update it to save the version that is working so that as I continue to make changes I don’t walk on what I’ve done. I need to know how to proceed.

I’ve set the dir to my project’s root folder and run git status. Here are the steps I think I need to take to accomplish a ‘point in time’ snapshot of all the code in my project:

  • git add . [As I understand it, this will put ALL my code files in the active root folder in the git staging area. I don’t need to issue a git init command because that is only used to initiate a new git repo. What happens to files in the repo whose names have been edited? Do they remain in the repo under the old names? If so, I will want to delete them because the renamed files take their place. Is there a ‘git replace all’ command that I need to learn about?]

  • git commit <repo_ID> --m “info to ID the commit” [As I understand it, this will prepare the files to be ‘pushed’ to the repo, but I don’t know the <repo_ID> value, or, for that matter, if one is needed because I have only the one local repo. I’m uncertain of the syntax for this command. ]

  • git push [As I understand it, this will cause git to put everything I pushed into the local repo and will resolve all deltas in content. How this happens is unclear to me. I’m uncertain of the syntax for this command, too.]

I’ve searched and read instructions online, but I didn’t find an example of what I describe, ie, pushing my entire project to the local repo with the intent to establish it as the current state of the repo.

I have NOT experimented with git commands for fear that I’ll screw up the repo and make a mess I don’t know how to fix.

I have 2 requests: 1) please comment on what I’ve posted above and point out what you think I don’t understand and 2) suggest things to read or exercises with git that I can learn from. Ultimately, I’m going to need to know what git commands to make in what order and the syntax for each command. When all is said and done, I want to have an updated repo that contains a snapshot of a point in time that does not have files that I no longer have in my local project folders.

the <repo_ID> thing is new to me. I always use git commit -m "commit message"

git tracks also deletion and renaming of files, if you use git add * you don’t need to worry.

You could even use git commit -a -m "commit message" and the -a flag removes the need to use the add command if you want to add all files. If you want to commit (save) only certain files then you need to use git add

git push takes the commits from your local repo and add them to the remote repo

the commits are the snapshots at a certain point in time, then with git push these snapshots are added to the remote repo


so, in short
you use git status, git add, and git commit in your local repo, git status shows if you have changes you have not saved, then you use git add to say which changes to save, and git commit to save those changes in a snapshot (commit)

then, git push would take the commits and copy them to the remote repo

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.