The GitHub repositories usually contain a README.md file to describe how to use the project. The GitHub web site has a simple editor, but it has a few limitations
- If you accidentally refresh the page, you lose your changes,
- The preview pane is wider than the page that will display your file, so the formatting can be different,
- You have to switch between the editor and the the preview every time you want to see the result.
One of the simplest ways to edit the README.md is to use the Atom editor.
- Open the README.md file with Atom,
- In the Packages menu select Markdown Preview, or press Ctrl-Shitft-M to open the preview pane.
As you type in the editor window the preview pane will show the live review of the file.
For the Markdown syntax visit https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf
If you work on a Windows computer and create a new GitHub repository, you can copy the code from the GitHub page to set the remote address and push the existing code to the GitHub server. You may get the following error message:
$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Make sure you have selected the HTTPS button to see the correct lines for Windows.
To change to address of the remote server execute the following
git remote set-url origin https://github.com/.....
If you use 2-factor authentication in GitHub, generate a 40 character Personal Access Token that you can use as a password to access GitHub repositories.
Create a Personal Access Token to use it as password in the Git client
- Log into GitHub and in the pull down at the upper right select Settings,
- On the left select Developer Settings,
- On the left select Personal access tokens,
- Click the Generate new token button,
- Enter a description for your token (so you can keep track and revoke them individually later, should you have a security breach),
- Select the repo checkbox,
- Click the Generate token button,
- Copy the token (40 characters long) to the clipboard and use that as your password on the command line.
Store or update your username and password in the Git credential helper
In macOS and Linux
Set the credential helper to store your username and password
To store the Git credentials on your hard disk in unencrypted form, use the Git Credential Store
git config credential.helper store
When you have already stored your password in the credential helper of Git and switching to 2-factor authentication, or just want to update your GitHub username or password
- In the command line execute the following to instruct the Git client to use the Wincred Windows credential helper to store your username and password
git config --global credential.helper wincred
- The next time you will access the GitHub repository to fetch, clone or push changes the Git CLI will pup up a dialog box to ask your username and password.
To update an already stored username or password in the Windows Credential Manager
When you access GitHub from your Windows workstation, Windows stores your credentials in the Credential Manager. If you want to enter an updated password, enter your personal access token when you switch to 2-factor authentication or switch between GitHub accounts, delete the GitHub entry from the Credential Manager.
- Open the Windows Credential Manager
- Open a command window
control /name Microsoft.CredentialManager
- On the Windows Credentials tab click the down arrow next to github.com
- Click the Remove link
- Click Yes to delete the link.
Branching and Merging are very powerful features in Git.
There are may branching strategies, my favorite is well explained at http://nvie.com/posts/a-successful-git-branching-model/
Pick any model you like and stick to it for a while to better understand and evaluate it. If you do not like that try another one.
In this model when we start to work on a new feature we
- Create a new branch (let’s call it feature) based on the develop branch and switch to it.
- Develop the new feature in the feature branch and add the changes to the repository.
- Before merging the changes of the feature branch back into the develop branch get the latest changes from the develop branch, apply your changes on top of them and test the application
- If there are merge conflicts, launch the Merge Tool. See Merging in Git with four panels in Windows to set up and use a great merge tool.
- It is possible that you will encounter merge conflicts in the same file multiple times. Just repeat the git mergetool command as many times as needed.
- When you are done with merging, complete the rebase
- Add and commit your changes in the feature branch
- When you have tested the code of the new feature, merge it back to the develop branch.
Switch back to the develop branch and merge the changes from the feature branch.
- If there are any merge conflicts, Git will ask you to resolve them.
I have accidentally included a folder in my Git repository, that I don’t want to include in source control. I wanted to remove it from the Git index, but not from the local hard drive.
The solution is the following command
git rm -r --cached myFolder
If the folder name contains spaces enclose it in quotes "my folder"
This will remove the folder from the Git repository, but leave it on the local drive.