Git
Ignoring Files and Directories in Git (.gitignore)
gitignore.io - Create useful .gitignore files for your project: Site, Documentation
Git Essentials
Offline:
Useful Git Guides
Setting the default branch name
git config --global init.defaultBranch main
You only have to do this once. Now all new repositories you create with git init will have a default branch named main.
Renaming the default branch for an existing repository(source)
-
Rename the local
masterbranch tomain, i.e. use the--movecommand in Git to copy the entiremasterbranch to a new branch calledmaingit branch -m master main -
Check that the renaming worked
git statusIf the renaming was successful you should see:
On branch main Your branch is up to date with 'origin/master'. nothing to commit, working tree clean -
Rename the default branch for the remote repos
GitHub:
GitHub now allows you to rename any branch, including the default branch, from the web.
-
Rename the default branch from the web:

-
Update your local clone:
# Get the latest commits and branches from the remote git fetch origin # Create a new tracking connection with the new origin/main branch git branch -u origin/main main git remote set-head origin -a
GitLab:
-
Locally: push
mainto your remote repository:git push -u origin mainYou will then see an option to start a merge request which we are not going to do because we want
mainto become the default branch, notmaster. -
Change it on GitLab on your project:
- Go to Admin Area --> Settings --> Repository.
- Expand Default initial branch name.
- Change the default to main.
- Save changes.
The next time someone clones your repository, they will automatically be on the
mainbranch. When they make changes, the link to create a merge request will automatically be pointed at themainbranch. -
Remove the master branch:
You can remove the
masterbranch completely. Removing themasterbranch is recommended to avoid any confusion around what branch is the default one. If you choose to remove themasterbranch make sure you update any dependencies.To remove the
masterbranch:- In your project go to Repository --> Branches.
- Under Active branches find master.
- Click the trash can to the right to delete the branch.
Add multiple pushurls for a given remote(orignin)
git remote set-url --add --push origin git://original/repo.git
git remote set-url --add --push origin git://another/repo.git
GitHub URL Shortener
Using git.io - a service provided by GitHub to shorten the URLs
Note
This URL shortener can only be used for GitHub URLs and not for other URLs.
Warning
You can create only one shortened URL for each URL. You cannot create another shortened URL if that GitHub URL has already been shortened. If you try to shorten the same URL again, it will return the existing shortened URL.
-
Option 1: Using
curlcommandcurl -i https://git.io -F "url=GITHUB_URL"- outputs url with arbitrary text after last slashcurl -i https://git.io -F "url=GITHUB_URL" -F "code=CUSTOM_TEXT"- outputs url with custom text after last slashcurl -i SHORTENED-URL- to retrieve the complete URL from the shortened URLIf you get SSL Error, then pass the
--insecureflag along with the command to skip certificate verification.The (un)shortened URL will appear in the
Locationfield of the response header. -
Option 2: Using following Python scripts
To create shortened URL:
import requests url = 'https://git.io/' data = {'url': 'https://github.com/jimit105/Intro-to-Deep-Learning-with-PyTorch', 'code': 'pytorch'} r = requests.post(url, data=data) print(r.headers.get('Location')) """ Output: https://git.io/pytorch """If you get
SSLErrorwhile running the above script, add the parameterverify=Falsein therequests.postmethod to skip certificate validation.To retrieve full URL:
import requests r = requests.head('https://git.io/pytorch') print(r.headers.get('Location')) """ Output: https://github.com/jimit105/Intro-to-Deep-Learning-with-PyTorch """
Deleting commited by mistake private data from git repo
Git Started Guide by ZTM
Conventional Commits(link)
Commit Messages Cheat Sheet(rus) -> link