Git Source Code Control
The purpose of this page is to point you to Git source code control resources.
- Become a git guru - provided my Atlassian - maker of bitbucket.org
- Getting Started with Git in 15 Minutes
- Best git innoculation
Setup on a New Machine
git config --global user.email "chuck@chuboe.com" git config --global user.name "Chuck Boecking" git config --global core.editor vim
Create new repository
Note: the below does not consider creating a .gitignore file.
cd /to/your/desired/directory/ git init git add . git commit -m 'init commit' git remote add origin ... #provided by github.com or gitlab git push -u origin master
Regular Commit and Push
git add . git push
Git Branch
See Branches:
git branch
Create a new branch from current branch:
git branch ll-11-20240419
Switch to a branch:
git switch ll-11-20240419
Push a newly created branch:
git push --set-upstream origin ll-11-20240419
Clone the newly created branch somewhere else:
git clone --branch ll-11-20240419 https://github.com/chuboe/idempiere-installation-script
See Changes
Not Added:
git diff
Changed in last commit where -p stands for patch and -1 means show last commit:
git log -p -1
Remember Me to Prevent Password on Push
You have two options when configuring git to remember your credentials.
Git Private Key
You might use a service like gitlab where you can pre-share keys. Update your ~/.ssh/config file to include something like the below. If your ~/.ssh/config does not exist, simple create one.
host my.some-ulr.org IdentityFile ~/.ssh/gitlab-chuboe
In your identify file (~/.ssh/gitlab-chuboe from above), you paste your openssh private key.
Git Token
If you are the only one using a computer, you can ask git to cache your password/token after first use. To establish the cache, issue the following command.
git config --global credential.helper cache
Or, you can save your credentials in a config file
git config --global credential.helper store
If you wish the system to forget your password, issue the following command:
git config --global --unset credential.helper
If you wish to extend the default timeout for 2 hours for 200 hours respectively:
git config --global credential.helper 'cache --timeout 7200' or git config --global credential.helper 'cache --timeout 7200000'
Reference:
- https://www.youtube.com/watch?v=kHkQnuYzwoo
- https://stackoverflow.com/questions/56377244/how-to-set-git-cache-timeout-for-long-period
Un-Add Files
There are time when you want to remove files you just added using the "git add" command. The following will remove them from the list of added files:
git reset
If you wish to also remove the changes themselves (and revert your working directory back to the state of the last commit):
git reset --hard
Revert the Last Commit
git log # shows the last couple of commits
git revert HEAD # reverts the last commit by creating a new commit
Git for Large Files
There are times when you need to store large, binary files in your git repository. This concept is common for us. We typically create two repositories per project: 1. for code and 2. one for deployment artifacts. Deployment artifacts are typically binary and large.
This is a good git tool to help reduce the overall size of your repository when managing these large files: https://git-lfs.com/.
sudo apt install git-lfs cd (to your desired code directory perform 'git init' if needed) git lfs install ... follow instructions above from here ...