Git and GitHub cheatsheet
Git / github cheatsheet Installation of git Download git from here or use on debian based linux 1 2 sudo apt update sudo apt install git Check if git is installed 1 git --version Configure git 1 2 git config --global user.name "Your Name" git config --global user.email "Your email" (Optional) Change the default brach name from master to main 1 git config --global init.defaultBranch main Configuring SSH keys to github Run these commands on the terminal 1 2 3 4 ssh-keygen -t ed25519 -C "$Your email" eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 cat ~/.ssh/id_ed25519.pub Go to Github>Settings>SSH and GPG keys. Click on New SSH key. Give a title and paste the key in the key field. Click on Add SSH key. The key should be available from the last command on the terminal. Git commands git init - initialize a git repository git add <file> - add a file to the staging area git add . - add all files to the staging area git add -A - add all files to the staging area git commit -m "message" - commit changes to the local repository git push - push changes to the remote repository git push -u origin <branch_name> - push changes to a branch git push origin <branch_name> - push changes to a branch git pull - pull changes from the remote repository git pull origin <branch_name> - pull changes from a branch git status - check the status of the repository git log - view the commit history git branch - view the branches git branch <branch_name> - create a new branch git checkout <branch_name> - switch to a branch git checkout -b <branch_name> - create and switch to a branch git merge <branch_name> - merge a branch into the current branch git clone <url> - clone a remote repository git remote add origin <url> - add a remote repository git remote -v - view the remote repositories git remote set-url origin <url> - change the url of the remote repository git remote remove origin - remove the remote repository git submodule: git submodule is used to add a git repository inside another git repository. This is useful when you want to use a git repository inside another git repository. For example, you can use git submodule to add a git repository that contains a library to your project. This way, you can use the library in your project without having to copy the library files into your project directory. git submodule add <url> - add a submodule git submodule init - initialize the submodule git submodule update - update the submodule git submodule update --remote - update the submodule to the latest commit