Several cheat-sheets of different topics in .md format. Checkout the Github pages version.
Tell git to remember the password in future pushes during 3600 seconds:
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
Modify user and email globally:
git config --system user.name "username"
git config --system user.email "mailexample@mail"
Modify user and email for linux user:
git config --global user.name "globalname"
git config --global user.email "mailexampl@mail"
Modify user and email on current git repository:
git config --local user.name "nameproject"
git config --local user.email "mailexample@mail"
Check the user name:
git config --get user.name
git config --get user.email
An ssh key should locally exists, protected with a password (not sure if the same as the GH account), which public key should be added to the list of known keys on the GitHub account. To create a new ssh key pair locally:
ssh-keygen -t ed25519 -C "anemail@email.com"
Everytime we want to interact with the private repo, there should be an ssh session running and using this key, this can be done with:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_gh_key
It might be useful to setup an auxiliary script such as:
#!/bin/bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_github_1
in some directory (e.g. `~/.utilities/setup_github_ssh_key_1.sh, permissions 744).
Further, we could add an alias to invoke the script
cat ~/.bash_aliases
alias setup_gihub_key_1='source ~/.utilities/setup_github_ssh_key_1.sh'
Check in which branch you are working now:
git status
git branch
Create a new branch and switch to it
git checkout -b new_branch_name
Checkout to a specific tagged version of the code.
git checkout tags/v2.1.3
git branch -a
git pull --all
git branch develop
git checkout develop
git checkout -b newbranch
git branch -d branchname
Once you are in the desired branch, change the code and commit the changes
git add filechanged.py
git commit -m "description of change"
If the changes are correct, then merge with master
git checkout master
git merge newbranch
Delete a branch if not needed
git branch -d newbranch
Remove the last commit:
git reset --hard HEAD^
Remove the last 2 commits:
git reset --hard HEAD~2
Without --hard
flag the commits are removed but not the changes in the code.
Download all branches and commits from origin:
git fetch origin
Download commits and files from specific branch:
git fetch origin branch_name
Download all registered repositories and branches:
git fetch --all
To check the result of the command without actually applying changes:
git fetch ... --dry-run
Checkout changes from master to current branch
git pull origin master(main)
Checkout changes from specific branch to current branch
git pull origin branch_name
Add changes to specific files:
git add pathToFile
Add changes to current folder and subfolders
git add .
Add changes to all repository
git add -A
Remove files added with git add
:
git rm --cache pathtofile
or remove a complete folder
git rm -rf --cache pathtofolder
# Update progress in destination branch master
git checkout master
git pull
# Merge feature branch
git merge FEATURE_BRANCH_NAME
Then, on github create a pull request of the two branches.
Ignore certain files systematically when adding changes creating a .gitignore
file and adding the files
file1
file2
*.log
folder1
folder2/*
!folder2/subfolder_or_file_included
Return to main page