Git Basics
# Concept
…
# Workflow
- pull latest
- create new branch
- do work
- rebase against main/master
- resolve conflicts
- push to remote
- raise pull request
- discuss
- merge
# Setup
# Initializing Git Repo:
// create git repo in current dir:
|
|
// get version
|
|
# Staging Files
// add files to be tracked by git
|
|
This marks the file and tells git to pay attention to it when commiting to the commit history
// add all files from this directory and downwards
|
|
// stage all files in repo (also upwards)
|
|
// unstage files
|
|
# Status
// get insight into which files are staged, commited or untracked
|
|
# Configuration
// configure user info etc.
|
|
# Commit, Push & Pull
# Commits
Like a save point for all staged files
|
|
// get overview of commits
|
|
// compact layout
|
|
// show specifics of a commit
copy COMMITHASH from log and dod
|
|
// show changes since last commit
|
|
// add messages after commit
|
|
# Branches
Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use
git status
to see which branch that is.
// get current branch
|
|
// show all branches
|
|
// show remote branches
|
|
// rename branch to main
|
|
// create branch
|
|
// switch branch
|
|
// switch and create branch
|
|
// switch to main
|
|
// delete branch
|
|
# Push
// push the repository to the remote github repo
|
|
|
|
// push new branch to remote
|
|
or
|
|
# GitHub
# Configure SSH Keys
If you can’t push to your remote repo you might have to configure an ssh access
# Clone from Remote
// download / mirror remote repo to local machine
|
|
# Pull
// download changes from remote server
|
|
// get from specific branch
|
|
# Pull Requests
ask the repository owner on e.g. github to merge your changes to the main/master branch
# Merging
# Merge
// merge branch to current branch (main)
|
|
# Rebase
Assume the following history exists and the current branch is “topic”:
|
|
From this point, the result of either of the following commands:
//update current branch with changes that happend on master in the mean time
|
|
would be:
|
|
NOTE: The latter form is just a short-hand of git checkout topic
followed by git rebase master
. When rebase exits topic
will remain the checked-out branch.
# Misc
# .gitignore file
Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named
.gitignore
. You can find helpful templates for.gitignore
files at github.com/github/gitignore.
# Submodules
to be able to use git repos inside other git repos use submodules:
// install a git repo as a submodule into another repo
|
|
when cloning repos with submodules you get the folders but not the files
// to get the files of the submodules
|
|
// do it all in one step
|
|
sources / further reading: