Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Git
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Operations== ===Add File or Directory to be tracked or Modified to Stage=== Add is used for different purposes, one is to add a new file to tracked by the VCS (second is to add changes of tracked files to the stage for the next commit): [[File:git1.png|400px]] // see table above git add . // stages new files and modifications, without deletions (on the current directory and its subdirectories) git add <Filename> git add <Directoryname> // will add all non-empty recursively // obviously the --all parameter is not needed git add -u // stages modifications and deletions, without new files ===Clone a repository=== git clone /pfad/zum/repository git clone benutzername@host:/pfad/zum/repository ====Clone [[GitLab|GitLab]] Repository==== * goto to target directory e.g. ~/GitRepositories * copy GitLab URL [[File:CloneGitLab.PNG|400px]] * type clone command e.g. <code>git clone https://gitlab.com/UweHeuer/test4.git</code> ====Clone [[GitHub|GitHub]] Repository==== * go to target directory e.g. C:\Uwes\GitRepositories * copy GitHub URL [[File:GitHubRepoURL.JPG|400px]] * type clone command e.g. <code>git clone https://github.com/UweHeuer/patternLockTest.git</code> This creates a new directory. ===Compare Stage with Repo=== git diff --staged ===Compare Working directory and Stage=== git diff ===Delete File from Repository=== git rm <File> git commit ===Commit Changes=== git commit // will add all staged changes to the repository, in a cmd shell a editor is opened to specifiy the commit message in file .git/COMMIT_EDITMSG git commit -a [-m <COMMIT_MESSAGE>] // will add all changes (not only the staged) to the repository ===Delete a Repository=== Delete the folder which contains the repository. ===Fetch everything from Remote=== git fetch [remote-name] // e.g. git fetch origin => amongst others the tracking branch origin/master will be updated locally ===Make an existing Project Directory to a Git Repository/Create Repository=== * go into the directory and git init * this will create .git directory * then [[Git#Add_File_or_Directory_to_be_tracked|add files]] git add <FILENAME> // e.g. 'git .' or 'git add .\D1\F1.txt' * if needed connect to a remote repository git remote add [shortname for remote] [url] // e.g. git remote add origin https://gitlab.com/UweHeuer/test1.git // this will not create a new project remotely but just store the connection * commit changes git commit * push everything to remote git push -u origin master // on GitLab this will create a new project, -u is important to make master a tracking branch and origin/master the upstream branch * create a branch git checkout -b branch1 * add and commit files * push branch to remote git push -u origin branch1 // -u important to make branch1 a tracking branch (see git branch -vv) // if -u forgotten at the first call you can set the upstream branch later e.g. by git push -u origin branch1 ===Get an Overview of an Project=== * show remote repositories git remote -v // -v shows detailled path, if no remote repository there is no output * update the local repository git fetch ===Pull Something=== Often pull cancels because there are local changes, which often can be ignored. Therefore it could make sense to use stash commands before and after: git stash git pull git stash clear // deletes everything from stash area ===Push Something=== git push // if current branch is a tracking branch REMOTE_NAME and BRANCH_NAME not needed git push <REMOTE_NAME> <BRANCH_NAME> // e.g. git push origin branch1 git push -u <REMOTE_NAME> <BRANCH_NAME> // -u needed for the first time to make it a tracking branch ===Manage Branches=== ====Show Branches==== Currently checked-out branch has an asterik in front of the output: git branch // show all local branches git branch --merged [--no-merged] // show all local branches which are merged into the current branch (those w/o asterik could be deleted) git branch --no-merged // show all local branches which are not merged into the current branch git branch -r // shows only remote branches git branch -a // shows all branches (local, tracking and remote) git branch -vv // shows tracking information for local branches in the form: // <BRANCH_NAME> <SHA-1> [<REMOTE BRANCH>: ahead and behind comparison] <LAST_COMMIT_MESSAGE> git remote show origin // full picture about tracked branches and status ====Checkout a branch==== Checkout will not override changed files but will be aborted and show a warning: git checkout <BRANCH_NAME> // in new git versions it will if the the branch does not exist locally get the remote one (-t) git checkout -b <BRANCH_NAME> // creates a branch and checks it out, short of git branch <BRANCH_NAME> and git checkout <BRANCH_NAME> git checkout --track origin/<BRANCH_NAME> // create a local branch based on remote branch and checks it out git checkout -t origin/<BRANCH_NAME> // s.a. ====Merge Branches==== A merge of a branch into the master branch (s. [https://git-scm.com/book/de/v1/Git-Branching-Einfaches-Branching-und-Merging here]): git merge <BRANCHNAME> // <BRANCHNAME> => <CURRENT_BRANCH>, checkout the branch in which the merge should be performed before git checkout master git merge origin/master git checkout Branch1 git merge master // merge master into Branch1 ====Compare Branches==== git diff <BRANCH> <BRANCH> [--name-only] // e.g. git diff Branch1 master git diff master origin/master // compare local with remote branch, output for each file is diff --git <FILE VERSION A> <FILE VERSION B> ... --- <FILE VERSION A> +++ <FILE VERSION B> - <CONTENT FILE A> + <CONTENT FILE B> ====Track a branch==== git branch -u origin/<BRANCH_NAME> // sets the remote branch as upstream branch git checkout -b <NEW_BRANCH_NAME> <REMOTE>/<REMOTE_BRANCH_NAME> // creates a new branch as tracking branch git checkout --track <REMOTE>/<REMOTE_BRANCH_NAME> // does the same ====Delete a branch==== git branch -d <BRANCH_NAME> // deletes a local branch, but only if it was fully merged before, otherwise use -D option git branch -D <BRANCH_NAME> // deletes a local branch, regardless whether it has been merged before git push origin :<BRANCH_NAME> // delete a remote branch ===Show Repository History=== git reflog --date=local [<BRANCH>] // for full history git log // for commits ===Show Configuration=== git config --list git config --list --show-origin git config <CONFIG_NAME> // git config user.name ===Rename Directory=== git mv <OLD_NAME> <NEW_NAME> // rename (also) working directory in file system git commit -m "<COMMIT_MESSAGE>" git push // merge ... ===Show remote Repository=== git remote -v ===Show Status of a Repository/Current Branch=== git status On branch <BRANCHNAME> // shows current branch Changes to be committed: ... <STAGED_FILES_AND/OR_DIRECTORIES IN GREEN> Untracked files: <UNTRACKED_FILES_AND/OR_DIRECTORIES IN RED> ===Stashing changes=== git stash
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width