Are you starting out on your version control system journey and want to get started quickly? Using the File Explorer as the remote repository? Then read on!
I decided to write my own as I found that some cheatsheets do not have all the commands I needed, to get the ball rolling when I first started out. In this sheet, you will also find the commands for setting up a git remote repo on the file repository. The commands are mostly the same, but I sectioned out the commands for this special case here.
You will need to install git to get started.
Setting up
Command | Description |
---|---|
git config --global user-name ‘myname’ | Setup name. Name will appear in branches when you start doing commits |
git config --global user.email ‘me@example.com’ | Setup email |
git config --list | Check your setup in the config file. Press q to exit |
More ways to customize you setup here.
Using File Explorer as remote repository
If you are not using GitHub or other server-based tools to store your remote repository, here is how you set up an empty repo on File Explorer on Windows, like a drive in the network. This is an alternative to ‘Creating a new repository’ in Github to do things completely locally.
Command | Description |
---|---|
cd \\my-remote-folder\my_repo | Navigate to the remote folder on the network |
git init --bare | Initialise remote repository there |
Using Gitlab as remote repository
To work remotely the easiest way is to generate ssh keys on your workstation.
Navigate to your home directory. Check if a .ssh folder exists. Enter the ssh key folder and generate a pair of ssh keys.
Command | Description |
---|---|
ssh-keygen -t ed25519 -C “ |
Create two files. A private and public key in .ssh |
Leave the passkey blank if you do not want to always type your password when doing commits. A confirmation should be generated in the terminal if sucessful.
Navigate to Gitlab and clock on your profile icon>Edit profile> SSH Keys. Copy and paste the contents in the *.pub file, which is your public key under the section “Key”. Give it a name and optionally choose when this key shall expire. Leave blank if it shall never expire.
Command | Description |
---|---|
git clone git@gitlab.com:username/reponame.git | Clone your repository with the now set up ssh key |
Working locally
Command | Description |
---|---|
git init | Initialise a git repository |
git add filename.py | Brings file to staging area which stores info to next commit |
git add . | Add all files in current folder to staging |
git status | Check which files are in the staging area |
git commit -m “Type your message” | Commit |
mkdir .gitignore | Create .gitignore List file names in this file and commit .gitignore to see the ignore effects come into play. |
git branch | See which branch you are in |
git checkout -b | Create a new branch based on the current branch |
git checkout -b new_branch_name old_branch_name | Create a new branch based on an old |
git checkout other_branch | Go to the other branch |
git branch | Show all branches |
git merge other_branch | Merge other branch into current branch |
git log –oneline | Show all commits made in a branch |
Working remotely
Command | Description | |
---|---|---|
Generate ssh public and private key | ||
git clone \\my-remote-folder\my-repo | Clone a remote repo | |
git remote add origin \\my-remote-folder\my-repo | Set up the remote repository in your local repo. origin as the nickname of the remote repo you call in your local repo. File path can also be a hyperlink. |
|
git push -u origin main | Push the current branch to the remote repo, origin with branch name main | |
git remote -v | View all remote connections | |
git branch -r -v | View last commit in all branches | |
git push origin -delete main | Delete the remote branch main |