Version control
version control (also known as revision control, source control, or source code management) is a class of systems responsible for managing changes to computer programs, documents, large web sites, or other collections of information.
Other people are using Git (network effect)
Notes: Open source repositories registered on Ohloh Source
Software that handles source code versioning
A cloud service for remote hosting of git repositories + makes your life easier
see: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
see: https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html
see: https://ubuntu.com/tutorials/command-line-for-beginners#3-opening-a-terminal
Create a local repository
mkdir my_repo
cd my_repo
git init #Initialized empty Git repository
Create a file your first commit
echo "Some line" > file1.txt
git status #Look at the changes within your repository
Create your first commit
git add file1.txt
git commit -m "my first commit"
git status
See the changes
git log
See the changes on a graph
git log --oneline --graph
Introduce a bug in our “code”
echo "A bug" >> file1.txt
git status
Look at the differences with the previous version
git diff file1.txt
Commit the bug
git add file1.txt
git commit -m "commit with a bug"
git log --oneline
Undo the bug
git revert <commit> #Find <commit> with git log --oneline
You should see “Revert “commit with a bug””:
git log --oneline
See:
See: https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
Create a new branch from the master/main branch
git branch #Look at the existing branches
git checkout master #Go to branch master (or main)
git checkout -b new-feature # Create a new branch called "new-feature"
Introduce a new feature
echo "A new feature" >> file1.txt
git status #Look at the changes within your repo
Create a commit
git add -A #add changes from all tracked and untracked files
git commit -m "my new feature"
Merge the feature branch into the master branch.
git checkout master #Go to branch master (or main)
git merge new-feature
See the changes
git log --oneline --graph
(Optional) Delete the feature branch
git branch -d new-feature #delete branch "new-feature"
git branch #You should see only one branch
Source: https://nvie.com/posts/a-successful-git-branching-model/
git config --global user.name "Your Username"
git config --global user.email "your.email@email.com"
See installationgit.pdf
Create a new repository on Gitlab:
Clone the repository:
git clone git@gitlab.com:<your_username>/tuto.git
cd tuto
Create a README file and push
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
You don’t want to track every single file in your repository (.i.e. large output files)
At the root of your repository, create a file .gitignore
. Add the following:
# ignore all logs
*.log
# ignore file text2.txt
text2.txt
See: https://www.atlassian.com/git/tutorials/saving-changes/gitignore
Same as previously. But this time, need to “synchronize” with the central repository (on Gitlab)
git checkout master #Go to the branch master on your local machine
git fetch origin #Update info on the remote branch master (from Gitlab)
git reset --hard origin/master #Remove your local modifications and use the latest version from Gitlab
git checkout -b new-feature
echo "Cool new feature" > file1.txt
git add -A #Add all files
git commit -m "Message describing the commit" #Create a commit
git push -u origin new-feature
This step is done directly on Gitlab:
See: https://docs.gitlab.com/ee/topics/git/feature_branch_development.html
On your local machine
git checkout master
git pull
See the merge in the log
git log
git checkout -b feature2
echo "Feature 1 different" > file1.txt
echo "Another new feature" > file2.txt
git add -A #Add all files
git commit -m "Feature 2"
git push -u origin feature2
git checkout master
echo "Change feature 1 as well" > file1.txt
git add -A #Add all files
git commit -m "master branch changing"
git push
Click on “Merge locally” on follow the instructions:
Step 1. Fetch and check out the branch for this merge request
git fetch origin
git checkout 'feature2'
Step 2. Merge the branch and fix any conflicts that come up
git fetch origin
git checkout 'master'
git merge --no-ff 'feature2' #merge feature2 into master
You should see:
Auto-merging file1.txt
CONFLICT (content): Merge conflict in file1.txt
Automatic merge failed; fix conflicts and then commit the result.
<<<<<<< HEAD
Change feature 1 as well
=======
Feature 1 different
>>>>>>> feature2
Step 4. Push the result of the merge to GitLab
git add -A
git commit -m "resolving merge conflicts"
git push origin 'master'