General Flashcards
what is origin?
origin is an alias on your system for a particular remote repository. It’s not actually a property of that repository.
By doing
git push origin branchname
you’re saying to push to the origin repository. There’s no requirement to name the remote repository origin: in fact the same repository could have a different alias for another developer.
Remotes are simply an alias that store the URL of repositories.
In the push command, you can use remotes or you can simply use a URL directly. An example that uses the URL:
git push git@github.com:git/git.git master
Remotes are simply an alias that store the URL of repositories. You can see what URL belongs to each remote by using
git remote -v
This alias name is not hard coded and could be changed using following command prompt:
git remote rename origin mynewalias
“detached HEAD” state
usually when you do git checkout, you check out a branch, not a commit
however, you can also say git checkout SHA1 has of a specific commit
git checkout a05eff1
The HEAD pointer in Git determines your current working revision (and thereby the files that are placed in your project’s working directory). Normally, when checking out a proper branch name, Git automatically moves the HEAD pointer along when you create a new commit. You are automatically on the newest commit of the chosen branch.
When you instead choose to check out a commit hash, Git won’t do this for you. The consequence is that when you make changes and commit them, these changes do NOT belong to any branch.
This means they can easily get lost once you check out a different revision or branch: not being recorded in the context of a branch, you lack the possibility to access that state easily
So if you want, say, to see an older version, you can check out this particular commit into a new branch and then make commits to this branch
git checkout -b test-branch 56a4e5c08
HEAD
Woher weiß Git, auf welchem Branch Sie gegenwärtig sind? Es besitzt einen speziellen Zeiger namens HEAD. Zeiger auf den aktuellen Commit des aktuell ausgecheckten Branches
Bei Git handelt es sich bei HEAD um einen Zeiger auf den lokalen Branch, auf dem Sie sich gegenwärtig befinden.
Let’s say we have master and anotherbranch with the same last commit. Current branch is master. So HEAD is pointing to the latest commit on master.
when we do git checkout anotherbranch, our HEAD switches to point to the commit of this another branch. At the moment, it is the same commit as that on master
Beim Commit wird der HEAD automatisch auf diesen neuen Commit nach vorne verschoben. So anotherbranch is now one commit ahead of master
if we do git checkout master again after that, the head will point again to the old commit which is the latest on master
https://git-scm.com/book/de/v2/Git-Branching-Branches-auf-einen-Blick
With the “git checkout” command,
you determine which revision of your project you want to work on. Git then places all of that revision’s files in your working copy folder.
if you have changed a file and want to restore it to the state it is in the index, don’t delete the file first, just do
git checkout – path/to/foo
If you would like to incorporate the changes you made in branch tmp into master
run git merge tmp from the master branch.
list all local branches
git branch
list all local and remote branches
git branch -a
list all remote branches
git branch -r
Merge into the current branch the remote branch next
git pull origin next
get remote branch master into your local repo, without pulling it into working space
git fetch origin master
Print all refs from remote (branches, tags, …):
git ls-remote origin
How can I tell a local branch to track a remote branch?
git branch -u origin/dev
In cases when you simply forgot, you can set (or change) a tracking relationship for your current HEAD branch at any time