Home Git and Github useful commands
Post
Cancel

Git and Github useful commands

Git is a distributed version control system (DVCS) that is used to track changes in computer files. It is often used for coordinating work among programmers collaboratively developing source code during software development.

Git cheat sheet

Git CommandUsage
git initinitialize an existing directory as a Git repository
git clone retrieve an entire repository from a hosted location via URL
git statusshow modified files in working directory, staged for your next commit
git add [. or file]add a file as it looks now to your next commit (stage)
git diffdiff of what is changed but not staged
git commit -mcommit your staged content as a new commit snapshot
git branchlist your branches. a * will appear next to the currently active branch
git branch [branch-name]create a new branch at the current commit
git checkoutswitch to another branch and check it out into your working directory
git merge [branch]switch to another branch and check it out into your working directory
git logshow all commits in the current branch’s history
git log branchB..branchAshow the commits on branchA that are not on branchB
git push Transmit local branch commits to the remote repository branch
git pull fetch and merge any commits from the tracking remote branch
git fetch fetch down all the branches from that Git remote
git reset --hard [commit]clear staging area, rewrite working tree from specified commit
git stashSave modified and staged changes

Git clone branch

1
git clone --depth 1 --branch 16.0 [email protected]:odoo/odoo.git

Git configuration

Git Config

1
2
3
4
git config --global user.name "Mohamed Elbagoury" 
git config --global user.email "[email protected]"
git remote add origin [email protected]:Elbagoury/odoo.git
git push --set-upstream google staging

Generate SSH key

1
2
ssh-keygen -t rsa -C "[email protected]"
cat  ~/.ssh/id_rsa.pub

Generate gpg key for github

1
2
3
4
5
6
7
gpg --full-generate-key
gpg --armor --output mypublic.key --export '[email protected]' # then copy to github
git config --global --unset gpg.format
git config --global user.signingkey # take after sec 3AA5C34371567BD2
export GPG_TTY=$(tty)
echo "test" | gpg --clearsign
git config --global commit.gpgsign true

Remember git passphrase in WSL

1
2
3
4
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
sudo apt install keychain
# inside ~/.bashrc add 
eval `keychain --quiet --eval --agents ssh id_rsa`
This post is licensed under CC BY 4.0 by the author.