Before you can commit your work to local or remote repositories you need to make sure git is tracking the file you have changed, otherwise those changes won't sync. To add a specific file to the git repository run the command:
Now when you do a commit this file will be tracked and if you make changes to it in the future that will be tracked also. You only need to add the file once.
There are times when you want to exclude certain files from your git repository. These could be credential files or something more harmless like ```_DS_Store``` folders that get created when you look at images. A ```.gitignore``` file specifies intentionally untracked files that Git should ignore, and thus keeps those files from being committed even when you run ```git add .```. To create this file:
When working with commits it's good practice to add a commit message that describes the changes you've made. This is also why it's good to make frequent commits and split your work into smaller units of work, meaning the commit message is simpler to create and more accurate. There are a couple of ways you can add the commit message from the command line, the first is the way I tend to use because you get to see a nice easy to read list of things that have changed and maybe files you've forgot to include. It opens up your default text editor for you to write the commit message in, yet again in my case this is vim. If you are wondering how to exit vim it's ``ESC`` then ``:wq``. This commit in this way do the following:
If you realise you've made a mistake and want to change the last commit, you don't have to create a new commit, you can use the ```-—amend``` flag to amend the most recent commit
Right so you're committed this is good. If you remember back to our diagram about the stages of a git repository you've now moved the files into the local repository. It's now time to sync them back up to the remote repository. Now this is pretty simple just run the following command:
<pxmlns:cc="http://creativecommons.org/ns#"xmlns:dct="http://purl.org/dc/terms/"><aproperty="dct:title"rel="cc:attributionURL"href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <arel="cc:attributionURL dct:creator"property="cc:attributionName"href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <ahref="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1"target="_blank"rel="license noopener noreferrer"style="display:inline-block;">CC BY-NC 4.0<imgstyle="height:22px!important;margin-left:3px;vertical-align:text-bottom;"src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"alt=""><imgstyle="height:22px!important;margin-left:3px;vertical-align:text-bottom;"src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"alt=""><imgstyle="height:22px!important;margin-left:3px;vertical-align:text-bottom;"src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"alt=""></a></p>