Sometimes the command line is a better and more reliable way of pushing changes to a Git repository. The sync feature on the Windows client does something the Linux GUI client wasn’t doing, and the latter was refusing to update the remote directory.
First navigate the command line to the local github subdirectory for the project. Next thing is to check a few global variables, if the client hasn’t been set up already. The important ones are username/password and the text editor, otherwise you’d probably be stuck in vim if the ‘-m‘ option isn’t used for adding a commit message:
$ git config --global user.name "Michael"
$ git config --global user.email email@example.com
$ git config --global core.editor nano
It’s quite possible my local working directory was in a ‘detached HEAD state’, which basically means I could have actually been trying to modify an older version of the project instead of the current one – ‘git checkout [commit identifier]‘ allows this, and ‘git checkout master‘ will point the local directory back to the repository’s master branch.
The ‘pull‘ and ‘push‘ commands should ensure both local and remote directories are in sync again:
$git checkout [branch]
$git pull origin [branch]
$git push origin [branch]
The output should show everything being up to date at this point. This seems to retrieve all files and history, which might be intensive depending on the size of the project.
Submitting the Changes
To see the current status, the differences between the local and remote directories:
As we can see here, there are two updated files: index.html and main.css. Another two .ttf files were also deleted from the local directory. To commit the changes, both files must be ‘staged’ – the concept is the same as including and excluding files in Visual Studio’s Team Explorer before committing.
$git add [file1] [file2] [file3]
Running ‘git status‘ again lists the staged changes:
Now the changes are ready to commit:
$git commit -m "Updated home page and CSS"
The command without the ‘-m‘ option will open a text editor for entering the commit message.
Finally the changes need to be ‘pushed’ to the remote directory/server.
$git push origin master
Note the 7-digit hexadecimal numbers. These are the first part of the changes’ SHA fingerprints and their identifiers in the history log.
Restore / Recover
The change log can be viewed with the ‘git reflog‘ command, with identifiers and HEAD numbers. Either could be used for selecting entries.
To view the details of a specific entry, use the ‘git show‘ command again. The ‘git show [identifier]‘ command will print the SHA fingerprint, the date/time, change author, files and section(s) of code that were changed.
$git show [change identifier]
To revert to an older version of a file, we can checkout that file from an earlier commit:
$git checkout [commit] [filename]
Omitting the filename will revert everything in the local directory to the specified version. Because the checked out file might differ from the current version in the master branch, it should appear as another change to be committed.