GIT CHEATSHEET
WHAT IS GIT
Git is a versioning control system.
TERMINOLOGY
The concepts are straightforward, however the terms used may not be. So to ensure we are all on the same page, here is the terms that you are likely to encounter and their meaning
-
REMOTE -- This would be your git repository server.
-
LOCAL REPOSITORY -- This is the location where you copied or are working on the data came from or will go to the git remote
-
BRANCH -- Git can manage multiple versions of the data it stores. So with regards to an application development repository, you can have one branch be 1.0, another 1.1, 1.2, 1.3, etc. Typically this would be dev, testing, 1.0, 1.1, 2.0, 2.1, etc. It is standard practice to create a new branch from master (the main branch) to snapshot a certain version.
-
COMMIT -- Any change, addition, or deletion to a file or files that is applied from the local repository to the remote
-
PULL -- Retrieval of data from the remote
-
PULL REQUEST -- This is a request of the repository admins to receive new data from you, generally in terms of contributing work to said project. The pull here is in relationship to the server doing the pull.
-
PUSH -- Sending of local repostiory to the remote.
-
PUSH REQUEST -- This is a rarity, but in cases where there is a private server which does not allow anonymous browsing or pulling, a push from the remote to you.
-
MERGE -- This is the intelligent merging of generally a local repository into the remote's, however strictly speaking its any two repositories histories are synced up, generally a local and the remote's.
-
MERGE REQUEST -- The same as a pull request.
WHAT TO CONTROL
Anything really. I personally use it for this site, personal code projects, backing up things ...
USAGE
To get started you will first need to setup your git account. Then you can clone/push/pull files as need be.
ACCOUNT SETUP
This isn't going to a website necessarily to create and register. This is telling git some basics. Now, on fancier tools such as GitLab or GitHub, you can use your ssh public key for authenticating to your repos. But for less fancy things you will need to setup a email/password combination. Additional options are the editor used for the commit messages, and your diff tool. Some GUI tools can handle reading this in, and modifying them. I use only linux and the terminal for my tasks, so I can't speak for OSX/Windows GUI tools at all, and have only briefly used a few linux ones (GitCola, GitG).
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor emacs
git config --global merge.tool vimdiff
git config credential.helper store
Check your settings:
git config --list
CLONE
This will be the first pull done, presuming you have nothing and need to be current with whatever branch you are going to be working with. Some projects are utilizing multiple branches, others just one.
git clone URL_OF_REPO
PULL
As changes are made by those that have modification rights, you will obviously need to grab them. This is a pull.
git pull
PUSH
If you were are someone who is authorized to make changes (commits), have made them, and would like to upload commits to the repo, this is called a push.
git add .
git commit -m "Commit comment"
git push -u REPO BRANCH #If you are already set to the proper repo/branch you can omit this and just do a "git push"
Example to a GitLab repo:
git push -u origin master
I MUCKED SOMETHING UP AND CANNOT RE-PULL
Presuming you are using origin/master for your repo & branch
git fetch --all
git reset --hard origin/master
CREATE NEW REPO AND ADD LOCAL FILES TO IT
-
Create new git repo
-
Change the default branch if desired via the web UI
-
cd to folder with your local files
-
Init your local dir to be a git repo
git init
-
Add the gitea repo as your remote
git remote add origin https://url/project.git
-
Add local files to repo
git add .
-
Commit them
git commit -m "Your commit message."
-
Set the branch and push them to the repo. Gitea default is main, Github and most others is master. Double check what you created and replicate the proper branch here.
git push --set-upstream origin master
-
Refresh your page on gitea and the files should be present
-
Further pushes will just be the following, as the current banch has already been set.
git push