β¦ π 2 min, π 5 min
Git Bash Here
.README.md
file in yourrepository (like this one) that gives a description of your project.You can write the README
file using the Markdown descriptive language .git clone
command. The actual url will depend on your username and repository, but forthis repository this command would look like this:git clone git@bitbucket.org:ZigaBrencic/new_developer.git
Once you have a local copy you will never have to call git clone
for thisrepository again.You have at your disposal the following basic commands:git pull
pull new changes from the remote server to your local copy,git push
push changes from your local copy to the remote server,git add
add all changes in
to __staging__,git reset
reverse git add
,git commit -m
commit all changes that are in __staging__,git checkout
revert all files in local directory to what they were after commit
(be careful here you can loose uncommited changes you've made),git status
view the current state of your local copy,git log
view the history of commits in this repository,git diff
show all unstaged changes in your local copy.mkdir git_intro
git init
git remote add origin https://gitlab.ethz.ch/ziga.brencic/git_intro.git
git add .
git commit -m "Initial commit"
git push -u origin master
$ git status # Make sure I have no local changes
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
$ git pull # Get new changes from remote server
Already up to date.
$ touch new_file.txt # Create a new file
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
new_file.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add new_file.txt # Add new file to staging
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: new_file.txt
$ git commit -m "Create new file" # Commit the changes
[master 6b1ff71] Create new file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 new_file.txt
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
$ git push # Push the new file into the remote repository
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 315 bytes | 315.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlab.ethz.ch/ziga.brencic/git_intro.git
817f344..6b1ff71 master -> master
master
branch, which is thedefault branch name.You can create a new branch with the commandgit branch
You can switch between branches with the commandgit checkout
master
branch.There are two ways of joining branches; merging branches and rebasing branches.git merge
- merges
into the current branch andcreates a so-called merge commit where it commits the different changes fromboth branches.git rebase
- applies the changes from
and thenre-applies the changes of the current branch on top.$ git branch new-feature # Create a new branch
$ git checkout new-feature # Move to the new brach
$ echo "Adding a line to README" >> README.md # Edit a file
$ git add README.md # Add a file to staging
$ git commit -m "Update README" # Commit the file
$ git checkout master # Move back to the master branch
$ git pull # Fetch the new changes on master
$ git checkout new-feature # Move back to the new branch
$ git rebase master # Join changes from master to the new branches
$ git checkout master # Move to the master branch
$ git merge new-feature # Merge the changes into the master branch
Get notified & read regularly π